@@ -17,7 +17,6 @@ use rustc_span::symbol::Symbol;
1717use rustc_span:: { BytePos , Pos , Span } ;
1818use rustc_target:: abi:: VariantIdx ;
1919use tracing:: { debug, instrument} ;
20- use util:: visit_bindings;
2120
2221use crate :: build:: expr:: as_place:: PlaceBuilder ;
2322use crate :: build:: scope:: DropKind ;
@@ -701,7 +700,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
701700 initializer : PlaceBuilder < ' tcx > ,
702701 set_match_place : bool ,
703702 ) -> BlockAnd < ( ) > {
704- let mut candidate = Candidate :: new ( initializer. clone ( ) , irrefutable_pat, false , self ) ;
703+ let candidate = Candidate :: new ( initializer. clone ( ) , irrefutable_pat, false , self ) ;
704+ let built_tree = self . lower_match_tree (
705+ block,
706+ irrefutable_pat. span ,
707+ & initializer,
708+ irrefutable_pat. span ,
709+ vec ! [ candidate] ,
710+ false ,
711+ ) ;
712+ let [ branch] = built_tree. branches . try_into ( ) . unwrap ( ) ;
705713
706714 // For matches and function arguments, the place that is being matched
707715 // can be set when creating the variables. But the place for
@@ -722,7 +730,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
722730 // };
723731 // ```
724732 if let Some ( place) = initializer. try_to_place ( self ) {
725- visit_bindings ( & [ & mut candidate] , |binding : & Binding < ' _ > | {
733+ // Because or-alternatives bind the same variables, we only explore the first one.
734+ let first_sub_branch = branch. sub_branches . first ( ) . unwrap ( ) ;
735+ for binding in & first_sub_branch. bindings {
726736 let local = self . var_local_id ( binding. var_id , OutsideGuard ) ;
727737 if let LocalInfo :: User ( BindingForm :: Var ( VarBindingForm {
728738 opt_match_place : Some ( ( ref mut match_place, _) ) ,
@@ -733,20 +743,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
733743 } else {
734744 bug ! ( "Let binding to non-user variable." )
735745 } ;
736- } ) ;
746+ }
737747 }
738748 }
739749
740- let built_tree = self . lower_match_tree (
741- block,
742- irrefutable_pat. span ,
743- & initializer,
744- irrefutable_pat. span ,
745- vec ! [ candidate] ,
746- false ,
747- ) ;
748- let [ branch] = built_tree. branches . try_into ( ) . unwrap ( ) ;
749-
750750 self . bind_pattern (
751751 self . source_info ( irrefutable_pat. span ) ,
752752 branch,
0 commit comments