Rollup merge of #124917 - cardigan1008:issue-124819, r=pnkfelix

Check whether the next_node is else-less if in get_return_block

Fix #124819
This commit is contained in:
Matthias Krüger 2024-05-20 18:13:47 +02:00 committed by GitHub
commit ba1bb80b6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

View File

@ -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,
_ => {}
}
}

View File

@ -0,0 +1,5 @@
fn main() {
if true {
"" //~ ERROR mismatched types [E0308]
}
}

View File

@ -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`.