@@ -17,7 +17,6 @@ use rustc_span::symbol::Symbol;
17
17
use rustc_span:: { BytePos , Pos , Span } ;
18
18
use rustc_target:: abi:: VariantIdx ;
19
19
use tracing:: { debug, instrument} ;
20
- use util:: visit_bindings;
21
20
22
21
use crate :: build:: expr:: as_place:: PlaceBuilder ;
23
22
use crate :: build:: scope:: DropKind ;
@@ -701,7 +700,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
701
700
initializer : PlaceBuilder < ' tcx > ,
702
701
set_match_place : bool ,
703
702
) -> 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 ( ) ;
705
713
706
714
// For matches and function arguments, the place that is being matched
707
715
// can be set when creating the variables. But the place for
@@ -722,7 +730,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
722
730
// };
723
731
// ```
724
732
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 {
726
736
let local = self . var_local_id ( binding. var_id , OutsideGuard ) ;
727
737
if let LocalInfo :: User ( BindingForm :: Var ( VarBindingForm {
728
738
opt_match_place : Some ( ( ref mut match_place, _) ) ,
@@ -733,20 +743,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
733
743
} else {
734
744
bug ! ( "Let binding to non-user variable." )
735
745
} ;
736
- } ) ;
746
+ }
737
747
}
738
748
}
739
749
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
-
750
750
self . bind_pattern (
751
751
self . source_info ( irrefutable_pat. span ) ,
752
752
branch,
0 commit comments