From 73c52bc4dc8714a058854d113acd5e4a7c9c0785 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Mon, 19 Sep 2022 22:53:21 +0200 Subject: [PATCH] Fix scoping for let-else. --- compiler/rustc_mir_build/src/build/block.rs | 43 +++++++++++++-------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/block.rs b/compiler/rustc_mir_build/src/build/block.rs index 4bab583c960..fc1b301402b 100644 --- a/compiler/rustc_mir_build/src/build/block.rs +++ b/compiler/rustc_mir_build/src/build/block.rs @@ -221,27 +221,37 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let init = &this.thir[*initializer]; let initializer_span = init.span; - this.declare_bindings( - visibility_scope, - remainder_span, - pattern, - ArmHasGuard(false), - Some((None, initializer_span)), - ); - this.visit_primary_bindings( - pattern, - UserTypeProjections::none(), - &mut |this, _, _, _, node, span, _, _| { - this.storage_live_binding(block, node, span, OutsideGuard, true); - this.schedule_drop_for_binding(node, span, OutsideGuard); - }, - ); let failure = unpack!( block = this.in_opt_scope( opt_destruction_scope.map(|de| (de, source_info)), |this| { let scope = (*init_scope, source_info); this.in_scope(scope, *lint_level, |this| { + this.declare_bindings( + visibility_scope, + remainder_span, + pattern, + ArmHasGuard(false), + Some((None, initializer_span)), + ); + this.visit_primary_bindings( + pattern, + UserTypeProjections::none(), + &mut |this, _, _, _, node, span, _, _| { + this.storage_live_binding( + block, + node, + span, + OutsideGuard, + true, + ); + this.schedule_drop_for_binding( + node, + span, + OutsideGuard, + ); + }, + ); this.ast_let_else( block, init, @@ -306,7 +316,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ArmHasGuard(false), Some((None, initializer_span)), ); - this.expr_into_pattern(block, &pattern, init) // irrefutable pattern + this.expr_into_pattern(block, &pattern, init) + // irrefutable pattern }) }, )