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:
commit
ba1bb80b6b
@ -549,6 +549,7 @@ impl<'hir> Map<'hir> {
|
|||||||
Node::Block(Block { expr: None, .. }) => return None,
|
Node::Block(Block { expr: None, .. }) => return None,
|
||||||
// The current node is not the tail expression of its parent.
|
// 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 hir_id != e.hir_id => return None,
|
||||||
|
Node::Block(Block { expr: Some(e), ..}) if matches!(e.kind, ExprKind::If(_, _, None)) => return None,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
tests/ui/return/tail-expr-if-as-return.rs
Normal file
5
tests/ui/return/tail-expr-if-as-return.rs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
fn main() {
|
||||||
|
if true {
|
||||||
|
"" //~ ERROR mismatched types [E0308]
|
||||||
|
}
|
||||||
|
}
|
12
tests/ui/return/tail-expr-if-as-return.stderr
Normal file
12
tests/ui/return/tail-expr-if-as-return.stderr
Normal 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`.
|
Loading…
x
Reference in New Issue
Block a user