Skip to content

Commit

Permalink
Unrolled build for rust-lang#124917
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#124917 - cardigan1008:issue-124819, r=pnkfelix

Check whether the next_node is else-less if in get_return_block

Fix rust-lang#124819
  • Loading branch information
rust-timer authored May 20, 2024
2 parents 474bee7 + c811acb commit d87fa55
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ impl<'hir> Map<'hir> {
Node::Block(Block { expr: None, .. }) => return None,
// The current node is not the tail expression of its parent.
Node::Block(Block { expr: Some(e), .. }) if hir_id != e.hir_id => return None,
Node::Block(Block { expr: Some(e), ..}) if matches!(e.kind, ExprKind::If(_, _, None)) => return None,
_ => {}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/return/tail-expr-if-as-return.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
if true {
"" //~ ERROR mismatched types [E0308]
}
}
12 changes: 12 additions & 0 deletions tests/ui/return/tail-expr-if-as-return.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0308]: mismatched types
--> $DIR/tail-expr-if-as-return.rs:3:9
|
LL | / if true {
LL | | ""
| | ^^ expected `()`, found `&str`
LL | | }
| |_____- expected this to be `()`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.

0 comments on commit d87fa55

Please sign in to comment.