Skip to content

Commit ba1bb80

Browse files
authored
Rollup merge of #124917 - cardigan1008:issue-124819, r=pnkfelix
Check whether the next_node is else-less if in get_return_block Fix #124819
2 parents 29c603c + c811acb commit ba1bb80

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

compiler/rustc_middle/src/hir/map/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ impl<'hir> Map<'hir> {
549549
Node::Block(Block { expr: None, .. }) => return None,
550550
// The current node is not the tail expression of its parent.
551551
Node::Block(Block { expr: Some(e), .. }) if hir_id != e.hir_id => return None,
552+
Node::Block(Block { expr: Some(e), ..}) if matches!(e.kind, ExprKind::If(_, _, None)) => return None,
552553
_ => {}
553554
}
554555
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
if true {
3+
"" //~ ERROR mismatched types [E0308]
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/tail-expr-if-as-return.rs:3:9
3+
|
4+
LL | / if true {
5+
LL | | ""
6+
| | ^^ expected `()`, found `&str`
7+
LL | | }
8+
| |_____- expected this to be `()`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)