Skip to content

Commit 62318b3

Browse files
author
cardigan1008
committed
fix: Check whether next_node is else-less if in get_return_block
Fix #124819, where a if-less block causes a wrong output. It is caused by get_return_block in get_fn_decl. In get_return_block, when a else-less if expression is the tail expression, the check for next_node will keep iterating. So it is necessary to make a early return in the check.
1 parent c54301f commit 62318b3

File tree

1 file changed

+1
-3
lines changed
  • compiler/rustc_middle/src/hir/map

1 file changed

+1
-3
lines changed

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

+1-3
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
}
@@ -563,9 +564,6 @@ impl<'hir> Map<'hir> {
563564
// We verify that indirectly by checking that the previous node is the
564565
// current node's body
565566
if node.body_id().map(|b| b.hir_id) == prev_hir_id => {
566-
if let Node::Expr(Expr { kind: ExprKind::Block(_, _), ..}) = self.tcx.hir_node(prev_hir_id.unwrap()) {
567-
return None;
568-
}
569567
return Some(hir_id)
570568
}
571569
// Ignore `return`s on the first iteration

0 commit comments

Comments
 (0)