only introduce a guard scope for arms with guards

This commit is contained in:
dianne
2025-08-07 16:17:54 -07:00
parent b2241c78c8
commit 0bdaef5b63
5 changed files with 39 additions and 23 deletions

View File

@@ -198,12 +198,12 @@ 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 {
// 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;
resolve_cond(visitor, guard);
}
resolve_expr(visitor, arm.body, false);