@@ -595,16 +595,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
595
595
// informs variant patterns, but nothing else.
596
596
(
597
597
& TestKind :: Switch { adt_def : tested_adt_def, .. } ,
598
- & PatKind :: Variant { adt_def, variant_index, ref subpatterns , .. } ,
598
+ & PatKind :: Variant { adt_def, variant_index, .. } ,
599
599
) => {
600
600
assert_eq ! ( adt_def, tested_adt_def) ;
601
- self . candidate_after_variant_switch (
602
- match_pair_index,
603
- adt_def,
604
- variant_index,
605
- subpatterns,
606
- candidate,
607
- ) ;
601
+ let match_pair = candidate. match_pairs . remove ( match_pair_index) ;
602
+ candidate. match_pairs . extend ( match_pair. subpairs ) ;
608
603
Some ( variant_index. as_usize ( ) )
609
604
}
610
605
@@ -619,7 +614,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
619
614
if is_switch_ty ( match_pair. pattern . ty ) =>
620
615
{
621
616
let index = options. get_index_of ( value) . unwrap ( ) ;
622
- self . candidate_without_match_pair ( match_pair_index, candidate ) ;
617
+ candidate . match_pairs . remove ( match_pair_index) ;
623
618
Some ( index)
624
619
}
625
620
@@ -645,13 +640,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
645
640
( Ordering :: Equal , & None ) => {
646
641
// on true, min_len = len = $actual_length,
647
642
// on false, len != $actual_length
648
- self . candidate_after_slice_test (
649
- match_pair_index,
650
- candidate,
651
- prefix,
652
- slice,
653
- suffix,
654
- ) ;
643
+ let match_pair = candidate. match_pairs . remove ( match_pair_index) ;
644
+ candidate. match_pairs . extend ( match_pair. subpairs ) ;
655
645
Some ( 0 )
656
646
}
657
647
( Ordering :: Less , _) => {
@@ -683,13 +673,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
683
673
( Ordering :: Equal , & Some ( _) ) => {
684
674
// $actual_len >= test_len = pat_len,
685
675
// so we can match.
686
- self . candidate_after_slice_test (
687
- match_pair_index,
688
- candidate,
689
- prefix,
690
- slice,
691
- suffix,
692
- ) ;
676
+ let match_pair = candidate. match_pairs . remove ( match_pair_index) ;
677
+ candidate. match_pairs . extend ( match_pair. subpairs ) ;
693
678
Some ( 0 )
694
679
}
695
680
( Ordering :: Less , _) | ( Ordering :: Equal , & None ) => {
@@ -713,7 +698,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
713
698
714
699
( TestKind :: Range ( test) , PatKind :: Range ( pat) ) => {
715
700
if test == pat {
716
- self . candidate_without_match_pair ( match_pair_index, candidate ) ;
701
+ candidate . match_pairs . remove ( match_pair_index) ;
717
702
return Some ( 0 ) ;
718
703
}
719
704
@@ -751,7 +736,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
751
736
// FIXME(#29623) we can be more clever here
752
737
let pattern_test = self . test ( match_pair) ;
753
738
if pattern_test. kind == test. kind {
754
- self . candidate_without_match_pair ( match_pair_index, candidate ) ;
739
+ candidate . match_pairs . remove ( match_pair_index) ;
755
740
Some ( 0 )
756
741
} else {
757
742
None
@@ -760,57 +745,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
760
745
}
761
746
}
762
747
763
- fn candidate_without_match_pair (
764
- & mut self ,
765
- match_pair_index : usize ,
766
- candidate : & mut Candidate < ' _ , ' tcx > ,
767
- ) {
768
- candidate. match_pairs . remove ( match_pair_index) ;
769
- }
770
-
771
- fn candidate_after_slice_test < ' pat > (
772
- & mut self ,
773
- match_pair_index : usize ,
774
- candidate : & mut Candidate < ' pat , ' tcx > ,
775
- prefix : & ' pat [ Box < Pat < ' tcx > > ] ,
776
- opt_slice : & ' pat Option < Box < Pat < ' tcx > > > ,
777
- suffix : & ' pat [ Box < Pat < ' tcx > > ] ,
778
- ) {
779
- let removed_place = candidate. match_pairs . remove ( match_pair_index) . place ;
780
- self . prefix_slice_suffix (
781
- & mut candidate. match_pairs ,
782
- & removed_place,
783
- prefix,
784
- opt_slice,
785
- suffix,
786
- ) ;
787
- }
788
-
789
- fn candidate_after_variant_switch < ' pat > (
790
- & mut self ,
791
- match_pair_index : usize ,
792
- adt_def : ty:: AdtDef < ' tcx > ,
793
- variant_index : VariantIdx ,
794
- subpatterns : & ' pat [ FieldPat < ' tcx > ] ,
795
- candidate : & mut Candidate < ' pat , ' tcx > ,
796
- ) {
797
- let match_pair = candidate. match_pairs . remove ( match_pair_index) ;
798
-
799
- // So, if we have a match-pattern like `x @ Enum::Variant(P1, P2)`,
800
- // we want to create a set of derived match-patterns like
801
- // `(x as Variant).0 @ P1` and `(x as Variant).1 @ P1`.
802
- let downcast_place = match_pair. place . downcast ( adt_def, variant_index) ; // `(x as Variant)`
803
- let consequent_match_pairs = subpatterns. iter ( ) . map ( |subpattern| {
804
- // e.g., `(x as Variant).0`
805
- let place = downcast_place
806
- . clone_project ( PlaceElem :: Field ( subpattern. field , subpattern. pattern . ty ) ) ;
807
- // e.g., `(x as Variant).0 @ P1`
808
- MatchPair :: new ( place, & subpattern. pattern , self )
809
- } ) ;
810
-
811
- candidate. match_pairs . extend ( consequent_match_pairs) ;
812
- }
813
-
814
748
fn error_simplifiable < ' pat > ( & mut self , match_pair : & MatchPair < ' pat , ' tcx > ) -> ! {
815
749
span_bug ! ( match_pair. pattern. span, "simplifiable pattern found: {:?}" , match_pair. pattern)
816
750
}
0 commit comments