@@ -18,17 +18,14 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
18
18
use rustc_hir:: RangeEnd ;
19
19
use rustc_index:: Idx ;
20
20
use rustc_middle:: mir:: interpret:: { ErrorHandled , GlobalId , LitToConstError , LitToConstInput } ;
21
- use rustc_middle:: mir:: { self , BorrowKind , Const , Mutability , UserTypeProjection } ;
21
+ use rustc_middle:: mir:: { self , BorrowKind , Const , Mutability } ;
22
22
use rustc_middle:: thir:: {
23
23
Ascription , BindingMode , FieldPat , LocalVarId , Pat , PatKind , PatRange , PatRangeBoundary ,
24
24
} ;
25
25
use rustc_middle:: ty:: layout:: IntegerExt ;
26
- use rustc_middle:: ty:: {
27
- self , AdtDef , CanonicalUserTypeAnnotation , GenericArg , GenericArgsRef , Region , Ty , TyCtxt ,
28
- TypeVisitableExt , UserType ,
29
- } ;
26
+ use rustc_middle:: ty:: { self , CanonicalUserTypeAnnotation , Ty , TyCtxt , TypeVisitableExt } ;
30
27
use rustc_span:: def_id:: LocalDefId ;
31
- use rustc_span:: { ErrorGuaranteed , Span , Symbol } ;
28
+ use rustc_span:: { ErrorGuaranteed , Span } ;
32
29
use rustc_target:: abi:: { FieldIdx , Integer } ;
33
30
34
31
use std:: cmp:: Ordering ;
@@ -701,146 +698,3 @@ impl<'tcx> UserAnnotatedTyHelpers<'tcx> for PatCtxt<'_, 'tcx> {
701
698
self . typeck_results
702
699
}
703
700
}
704
-
705
- trait PatternFoldable < ' tcx > : Sized {
706
- fn fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
707
- self . super_fold_with ( folder)
708
- }
709
-
710
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self ;
711
- }
712
-
713
- trait PatternFolder < ' tcx > : Sized {
714
- fn fold_pattern ( & mut self , pattern : & Pat < ' tcx > ) -> Pat < ' tcx > {
715
- pattern. super_fold_with ( self )
716
- }
717
-
718
- fn fold_pattern_kind ( & mut self , kind : & PatKind < ' tcx > ) -> PatKind < ' tcx > {
719
- kind. super_fold_with ( self )
720
- }
721
- }
722
-
723
- impl < ' tcx , T : PatternFoldable < ' tcx > > PatternFoldable < ' tcx > for Box < T > {
724
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
725
- let content: T = ( * * self ) . fold_with ( folder) ;
726
- Box :: new ( content)
727
- }
728
- }
729
-
730
- impl < ' tcx , T : PatternFoldable < ' tcx > > PatternFoldable < ' tcx > for Vec < T > {
731
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
732
- self . iter ( ) . map ( |t| t. fold_with ( folder) ) . collect ( )
733
- }
734
- }
735
-
736
- impl < ' tcx , T : PatternFoldable < ' tcx > > PatternFoldable < ' tcx > for Box < [ T ] > {
737
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
738
- self . iter ( ) . map ( |t| t. fold_with ( folder) ) . collect ( )
739
- }
740
- }
741
-
742
- impl < ' tcx , T : PatternFoldable < ' tcx > > PatternFoldable < ' tcx > for Option < T > {
743
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
744
- self . as_ref ( ) . map ( |t| t. fold_with ( folder) )
745
- }
746
- }
747
-
748
- macro_rules! ClonePatternFoldableImpls {
749
- ( <$lt_tcx: tt> $( $ty: ty) ,+) => {
750
- $(
751
- impl <$lt_tcx> PatternFoldable <$lt_tcx> for $ty {
752
- fn super_fold_with<F : PatternFolder <$lt_tcx>>( & self , _: & mut F ) -> Self {
753
- Clone :: clone( self )
754
- }
755
- }
756
- ) +
757
- }
758
- }
759
-
760
- ClonePatternFoldableImpls ! { <' tcx>
761
- Span , FieldIdx , Mutability , Symbol , LocalVarId , usize ,
762
- Region <' tcx>, Ty <' tcx>, BindingMode , AdtDef <' tcx>,
763
- GenericArgsRef <' tcx>, & ' tcx GenericArg <' tcx>, UserType <' tcx>,
764
- UserTypeProjection , CanonicalUserTypeAnnotation <' tcx>
765
- }
766
-
767
- impl < ' tcx > PatternFoldable < ' tcx > for FieldPat < ' tcx > {
768
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
769
- FieldPat { field : self . field . fold_with ( folder) , pattern : self . pattern . fold_with ( folder) }
770
- }
771
- }
772
-
773
- impl < ' tcx > PatternFoldable < ' tcx > for Pat < ' tcx > {
774
- fn fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
775
- folder. fold_pattern ( self )
776
- }
777
-
778
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
779
- Pat {
780
- ty : self . ty . fold_with ( folder) ,
781
- span : self . span . fold_with ( folder) ,
782
- kind : self . kind . fold_with ( folder) ,
783
- }
784
- }
785
- }
786
-
787
- impl < ' tcx > PatternFoldable < ' tcx > for PatKind < ' tcx > {
788
- fn fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
789
- folder. fold_pattern_kind ( self )
790
- }
791
-
792
- fn super_fold_with < F : PatternFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
793
- match * self {
794
- PatKind :: Wild => PatKind :: Wild ,
795
- PatKind :: Error ( e) => PatKind :: Error ( e) ,
796
- PatKind :: AscribeUserType {
797
- ref subpattern,
798
- ascription : Ascription { ref annotation, variance } ,
799
- } => PatKind :: AscribeUserType {
800
- subpattern : subpattern. fold_with ( folder) ,
801
- ascription : Ascription { annotation : annotation. fold_with ( folder) , variance } ,
802
- } ,
803
- PatKind :: Binding { mutability, name, mode, var, ty, ref subpattern, is_primary } => {
804
- PatKind :: Binding {
805
- mutability : mutability. fold_with ( folder) ,
806
- name : name. fold_with ( folder) ,
807
- mode : mode. fold_with ( folder) ,
808
- var : var. fold_with ( folder) ,
809
- ty : ty. fold_with ( folder) ,
810
- subpattern : subpattern. fold_with ( folder) ,
811
- is_primary,
812
- }
813
- }
814
- PatKind :: Variant { adt_def, args, variant_index, ref subpatterns } => {
815
- PatKind :: Variant {
816
- adt_def : adt_def. fold_with ( folder) ,
817
- args : args. fold_with ( folder) ,
818
- variant_index,
819
- subpatterns : subpatterns. fold_with ( folder) ,
820
- }
821
- }
822
- PatKind :: Leaf { ref subpatterns } => {
823
- PatKind :: Leaf { subpatterns : subpatterns. fold_with ( folder) }
824
- }
825
- PatKind :: Deref { ref subpattern } => {
826
- PatKind :: Deref { subpattern : subpattern. fold_with ( folder) }
827
- }
828
- PatKind :: Constant { value } => PatKind :: Constant { value } ,
829
- PatKind :: InlineConstant { def, subpattern : ref pattern } => {
830
- PatKind :: InlineConstant { def, subpattern : pattern. fold_with ( folder) }
831
- }
832
- PatKind :: Range ( ref range) => PatKind :: Range ( range. clone ( ) ) ,
833
- PatKind :: Slice { ref prefix, ref slice, ref suffix } => PatKind :: Slice {
834
- prefix : prefix. fold_with ( folder) ,
835
- slice : slice. fold_with ( folder) ,
836
- suffix : suffix. fold_with ( folder) ,
837
- } ,
838
- PatKind :: Array { ref prefix, ref slice, ref suffix } => PatKind :: Array {
839
- prefix : prefix. fold_with ( folder) ,
840
- slice : slice. fold_with ( folder) ,
841
- suffix : suffix. fold_with ( folder) ,
842
- } ,
843
- PatKind :: Or { ref pats } => PatKind :: Or { pats : pats. fold_with ( folder) } ,
844
- }
845
- }
846
- }
0 commit comments