@@ -435,46 +435,50 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
435435 let arm_scope = ( arm. scope , arm_source_info) ;
436436 let match_scope = self . local_scope ( ) ;
437437 self . in_scope ( arm_scope, arm. lint_level , |this| {
438- let old_dedup_scope =
439- mem:: replace ( & mut this. fixed_temps_scope , Some ( arm. scope ) ) ;
440-
441- // `try_to_place` may fail if it is unable to resolve the given
442- // `PlaceBuilder` inside a closure. In this case, we don't want to include
443- // a scrutinee place. `scrutinee_place_builder` will fail to be resolved
444- // if the only match arm is a wildcard (`_`).
445- // Example:
446- // ```
447- // let foo = (0, 1);
448- // let c = || {
449- // match foo { _ => () };
450- // };
451- // ```
452- let scrutinee_place = scrutinee_place_builder. try_to_place ( this) ;
453- let opt_scrutinee_place =
454- scrutinee_place. as_ref ( ) . map ( |place| ( Some ( place) , scrutinee_span) ) ;
455- let scope = this. declare_bindings (
456- None ,
457- arm. span ,
458- & arm. pattern ,
459- arm. guard ,
460- opt_scrutinee_place,
461- ) ;
438+ let guard_scope =
439+ region:: Scope { data : region:: ScopeData :: MatchGuard , ..arm. scope } ;
440+ this. in_scope ( ( guard_scope, arm_source_info) , LintLevel :: Inherited , |this| {
441+ let old_dedup_scope =
442+ mem:: replace ( & mut this. fixed_temps_scope , Some ( guard_scope) ) ;
443+
444+ // `try_to_place` may fail if it is unable to resolve the given
445+ // `PlaceBuilder` inside a closure. In this case, we don't want to include
446+ // a scrutinee place. `scrutinee_place_builder` will fail to be resolved
447+ // if the only match arm is a wildcard (`_`).
448+ // Example:
449+ // ```
450+ // let foo = (0, 1);
451+ // let c = || {
452+ // match foo { _ => () };
453+ // };
454+ // ```
455+ let scrutinee_place = scrutinee_place_builder. try_to_place ( this) ;
456+ let opt_scrutinee_place =
457+ scrutinee_place. as_ref ( ) . map ( |place| ( Some ( place) , scrutinee_span) ) ;
458+ let scope = this. declare_bindings (
459+ None ,
460+ arm. span ,
461+ & arm. pattern ,
462+ arm. guard ,
463+ opt_scrutinee_place,
464+ ) ;
462465
463- let arm_block = this. bind_pattern (
464- outer_source_info,
465- branch,
466- & built_match_tree. fake_borrow_temps ,
467- scrutinee_span,
468- Some ( ( arm, match_scope) ) ,
469- ) ;
466+ let arm_block = this. bind_pattern (
467+ outer_source_info,
468+ branch,
469+ & built_match_tree. fake_borrow_temps ,
470+ scrutinee_span,
471+ Some ( ( arm, match_scope) ) ,
472+ ) ;
470473
471- this. fixed_temps_scope = old_dedup_scope;
474+ this. fixed_temps_scope = old_dedup_scope;
472475
473- if let Some ( source_scope) = scope {
474- this. source_scope = source_scope;
475- }
476+ if let Some ( source_scope) = scope {
477+ this. source_scope = source_scope;
478+ }
476479
477- this. expr_into_dest ( destination, arm_block, arm. body )
480+ this. expr_into_dest ( destination, arm_block, arm. body )
481+ } )
478482 } )
479483 . into_block ( )
480484 } )
@@ -2523,7 +2527,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
25232527 // bindings and temporaries created for and by the guard. As a result, the drop order
25242528 // for the arm will correspond to the binding order of the final sub-branch lowered.
25252529 if matches ! ( schedule_drops, ScheduleDrops :: No ) {
2526- self . clear_top_scope ( arm. scope ) ;
2530+ self . clear_match_arm_and_guard_scopes ( arm. scope ) ;
25272531 }
25282532
25292533 let source_info = self . source_info ( guard_span) ;
0 commit comments