about summary refs log tree commit diff
diff options
context:
space:
mode:
authorcardigan1008 <211250058@smail.nju.edu.cn>2024-05-09 23:44:54 +0800
committercardigan1008 <211250058@smail.nju.edu.cn>2024-05-09 23:44:54 +0800
commit62318b38ef591c70d9db875e88a04aa37c565828 (patch)
treea2261a64ee210fcfef5c3fb1d5faad1eea43c864
parentc54301f114d6fab44e8305da328eece26f682456 (diff)
downloadrust-62318b38ef591c70d9db875e88a04aa37c565828.tar.gz
rust-62318b38ef591c70d9db875e88a04aa37c565828.zip
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.
-rw-r--r--compiler/rustc_middle/src/hir/map/mod.rs4
1 files changed, 1 insertions, 3 deletions
diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs
index 0deafb73d0e..f4ecc0973ef 100644
--- a/compiler/rustc_middle/src/hir/map/mod.rs
+++ b/compiler/rustc_middle/src/hir/map/mod.rs
@@ -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,
                     _ => {}
                 }
             }
@@ -563,9 +564,6 @@ impl<'hir> Map<'hir> {
                     // We verify that indirectly by checking that the previous node is the
                     // current node's body
                     if node.body_id().map(|b| b.hir_id) == prev_hir_id =>  {
-                        if let Node::Expr(Expr { kind: ExprKind::Block(_, _), ..}) = self.tcx.hir_node(prev_hir_id.unwrap()) {
-                            return None;
-                        }
                         return Some(hir_id)
                 }
                 // Ignore `return`s on the first iteration