about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis
diff options
context:
space:
mode:
authordianne <diannes.gm@gmail.com>2025-07-03 06:10:37 -0700
committerdianne <diannes.gm@gmail.com>2025-08-07 16:43:20 -0700
commitb2241c78c86a15b8e7e842f036135df4478de0fe (patch)
tree68f79ca2b81adced88e3498f28433539e612bca5 /compiler/rustc_hir_analysis
parent4ec688110f21b04ab243c5a3e56997ea6c33dbcc (diff)
downloadrust-b2241c78c86a15b8e7e842f036135df4478de0fe.tar.gz
rust-b2241c78c86a15b8e7e842f036135df4478de0fe.zip
add a scope for `if let` guard temporaries and bindings
This ensures `if let` guard temporaries and bindings are dropped before
the match arm's pattern's bindings.
Diffstat (limited to 'compiler/rustc_hir_analysis')
-rw-r--r--compiler/rustc_hir_analysis/src/check/region.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs
index 95f6fba6487..d43ac053758 100644
--- a/compiler/rustc_hir_analysis/src/check/region.rs
+++ b/compiler/rustc_hir_analysis/src/check/region.rs
@@ -198,6 +198,11 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
     visitor.cx.var_parent = visitor.cx.parent;
 
     resolve_pat(visitor, arm.pat);
+    // We introduce a new scope to contain bindings and temporaries from `if let` guards, to
+    // ensure they're dropped before the arm's pattern's bindings. This extends to the end of
+    // the arm body and is the scope of its locals as well.
+    visitor.enter_scope(Scope { local_id: arm.hir_id.local_id, data: ScopeData::MatchGuard });
+    visitor.cx.var_parent = visitor.cx.parent;
     if let Some(guard) = arm.guard {
         resolve_cond(visitor, guard);
     }