@@ -45,6 +45,7 @@ pub mod mono;
45
45
mod query;
46
46
pub mod tcx;
47
47
pub mod traversal;
48
+ mod type_foldable;
48
49
pub mod visit;
49
50
50
51
/// Types for locals
@@ -2683,325 +2684,3 @@ impl Location {
2683
2684
}
2684
2685
}
2685
2686
}
2686
-
2687
- /*
2688
- * `TypeFoldable` implementations for MIR types
2689
- */
2690
-
2691
- CloneTypeFoldableAndLiftImpls ! {
2692
- BlockTailInfo ,
2693
- MirPhase ,
2694
- SourceInfo ,
2695
- FakeReadCause ,
2696
- RetagKind ,
2697
- SourceScope ,
2698
- SourceScopeData ,
2699
- SourceScopeLocalData ,
2700
- UserTypeAnnotationIndex ,
2701
- }
2702
-
2703
- impl < ' tcx > TypeFoldable < ' tcx > for Terminator < ' tcx > {
2704
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2705
- use crate :: mir:: TerminatorKind :: * ;
2706
-
2707
- let kind = match self . kind {
2708
- Goto { target } => Goto { target } ,
2709
- SwitchInt { ref discr, switch_ty, ref values, ref targets } => SwitchInt {
2710
- discr : discr. fold_with ( folder) ,
2711
- switch_ty : switch_ty. fold_with ( folder) ,
2712
- values : values. clone ( ) ,
2713
- targets : targets. clone ( ) ,
2714
- } ,
2715
- Drop { ref location, target, unwind } => {
2716
- Drop { location : location. fold_with ( folder) , target, unwind }
2717
- }
2718
- DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
2719
- location : location. fold_with ( folder) ,
2720
- value : value. fold_with ( folder) ,
2721
- target,
2722
- unwind,
2723
- } ,
2724
- Yield { ref value, resume, ref resume_arg, drop } => Yield {
2725
- value : value. fold_with ( folder) ,
2726
- resume,
2727
- resume_arg : resume_arg. fold_with ( folder) ,
2728
- drop,
2729
- } ,
2730
- Call { ref func, ref args, ref destination, cleanup, from_hir_call } => {
2731
- let dest =
2732
- destination. as_ref ( ) . map ( |& ( ref loc, dest) | ( loc. fold_with ( folder) , dest) ) ;
2733
-
2734
- Call {
2735
- func : func. fold_with ( folder) ,
2736
- args : args. fold_with ( folder) ,
2737
- destination : dest,
2738
- cleanup,
2739
- from_hir_call,
2740
- }
2741
- }
2742
- Assert { ref cond, expected, ref msg, target, cleanup } => {
2743
- use AssertKind :: * ;
2744
- let msg = match msg {
2745
- BoundsCheck { ref len, ref index } => {
2746
- BoundsCheck { len : len. fold_with ( folder) , index : index. fold_with ( folder) }
2747
- }
2748
- Overflow ( _)
2749
- | OverflowNeg
2750
- | DivisionByZero
2751
- | RemainderByZero
2752
- | ResumedAfterReturn ( _)
2753
- | ResumedAfterPanic ( _) => msg. clone ( ) ,
2754
- } ;
2755
- Assert { cond : cond. fold_with ( folder) , expected, msg, target, cleanup }
2756
- }
2757
- GeneratorDrop => GeneratorDrop ,
2758
- Resume => Resume ,
2759
- Abort => Abort ,
2760
- Return => Return ,
2761
- Unreachable => Unreachable ,
2762
- FalseEdges { real_target, imaginary_target } => {
2763
- FalseEdges { real_target, imaginary_target }
2764
- }
2765
- FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind } ,
2766
- } ;
2767
- Terminator { source_info : self . source_info , kind }
2768
- }
2769
-
2770
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2771
- use crate :: mir:: TerminatorKind :: * ;
2772
-
2773
- match self . kind {
2774
- SwitchInt { ref discr, switch_ty, .. } => {
2775
- discr. visit_with ( visitor) || switch_ty. visit_with ( visitor)
2776
- }
2777
- Drop { ref location, .. } => location. visit_with ( visitor) ,
2778
- DropAndReplace { ref location, ref value, .. } => {
2779
- location. visit_with ( visitor) || value. visit_with ( visitor)
2780
- }
2781
- Yield { ref value, .. } => value. visit_with ( visitor) ,
2782
- Call { ref func, ref args, ref destination, .. } => {
2783
- let dest = if let Some ( ( ref loc, _) ) = * destination {
2784
- loc. visit_with ( visitor)
2785
- } else {
2786
- false
2787
- } ;
2788
- dest || func. visit_with ( visitor) || args. visit_with ( visitor)
2789
- }
2790
- Assert { ref cond, ref msg, .. } => {
2791
- if cond. visit_with ( visitor) {
2792
- use AssertKind :: * ;
2793
- match msg {
2794
- BoundsCheck { ref len, ref index } => {
2795
- len. visit_with ( visitor) || index. visit_with ( visitor)
2796
- }
2797
- Overflow ( _)
2798
- | OverflowNeg
2799
- | DivisionByZero
2800
- | RemainderByZero
2801
- | ResumedAfterReturn ( _)
2802
- | ResumedAfterPanic ( _) => false ,
2803
- }
2804
- } else {
2805
- false
2806
- }
2807
- }
2808
- Goto { .. }
2809
- | Resume
2810
- | Abort
2811
- | Return
2812
- | GeneratorDrop
2813
- | Unreachable
2814
- | FalseEdges { .. }
2815
- | FalseUnwind { .. } => false ,
2816
- }
2817
- }
2818
- }
2819
-
2820
- impl < ' tcx > TypeFoldable < ' tcx > for GeneratorKind {
2821
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2822
- * self
2823
- }
2824
-
2825
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2826
- false
2827
- }
2828
- }
2829
-
2830
- impl < ' tcx > TypeFoldable < ' tcx > for Place < ' tcx > {
2831
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2832
- Place { local : self . local . fold_with ( folder) , projection : self . projection . fold_with ( folder) }
2833
- }
2834
-
2835
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2836
- self . local . visit_with ( visitor) || self . projection . visit_with ( visitor)
2837
- }
2838
- }
2839
-
2840
- impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx ty:: List < PlaceElem < ' tcx > > {
2841
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2842
- let v = self . iter ( ) . map ( |t| t. fold_with ( folder) ) . collect :: < Vec < _ > > ( ) ;
2843
- folder. tcx ( ) . intern_place_elems ( & v)
2844
- }
2845
-
2846
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2847
- self . iter ( ) . any ( |t| t. visit_with ( visitor) )
2848
- }
2849
- }
2850
-
2851
- impl < ' tcx > TypeFoldable < ' tcx > for Rvalue < ' tcx > {
2852
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2853
- use crate :: mir:: Rvalue :: * ;
2854
- match * self {
2855
- Use ( ref op) => Use ( op. fold_with ( folder) ) ,
2856
- Repeat ( ref op, len) => Repeat ( op. fold_with ( folder) , len) ,
2857
- Ref ( region, bk, ref place) => {
2858
- Ref ( region. fold_with ( folder) , bk, place. fold_with ( folder) )
2859
- }
2860
- AddressOf ( mutability, ref place) => AddressOf ( mutability, place. fold_with ( folder) ) ,
2861
- Len ( ref place) => Len ( place. fold_with ( folder) ) ,
2862
- Cast ( kind, ref op, ty) => Cast ( kind, op. fold_with ( folder) , ty. fold_with ( folder) ) ,
2863
- BinaryOp ( op, ref rhs, ref lhs) => {
2864
- BinaryOp ( op, rhs. fold_with ( folder) , lhs. fold_with ( folder) )
2865
- }
2866
- CheckedBinaryOp ( op, ref rhs, ref lhs) => {
2867
- CheckedBinaryOp ( op, rhs. fold_with ( folder) , lhs. fold_with ( folder) )
2868
- }
2869
- UnaryOp ( op, ref val) => UnaryOp ( op, val. fold_with ( folder) ) ,
2870
- Discriminant ( ref place) => Discriminant ( place. fold_with ( folder) ) ,
2871
- NullaryOp ( op, ty) => NullaryOp ( op, ty. fold_with ( folder) ) ,
2872
- Aggregate ( ref kind, ref fields) => {
2873
- let kind = box match * * kind {
2874
- AggregateKind :: Array ( ty) => AggregateKind :: Array ( ty. fold_with ( folder) ) ,
2875
- AggregateKind :: Tuple => AggregateKind :: Tuple ,
2876
- AggregateKind :: Adt ( def, v, substs, user_ty, n) => AggregateKind :: Adt (
2877
- def,
2878
- v,
2879
- substs. fold_with ( folder) ,
2880
- user_ty. fold_with ( folder) ,
2881
- n,
2882
- ) ,
2883
- AggregateKind :: Closure ( id, substs) => {
2884
- AggregateKind :: Closure ( id, substs. fold_with ( folder) )
2885
- }
2886
- AggregateKind :: Generator ( id, substs, movablity) => {
2887
- AggregateKind :: Generator ( id, substs. fold_with ( folder) , movablity)
2888
- }
2889
- } ;
2890
- Aggregate ( kind, fields. fold_with ( folder) )
2891
- }
2892
- }
2893
- }
2894
-
2895
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2896
- use crate :: mir:: Rvalue :: * ;
2897
- match * self {
2898
- Use ( ref op) => op. visit_with ( visitor) ,
2899
- Repeat ( ref op, _) => op. visit_with ( visitor) ,
2900
- Ref ( region, _, ref place) => region. visit_with ( visitor) || place. visit_with ( visitor) ,
2901
- AddressOf ( _, ref place) => place. visit_with ( visitor) ,
2902
- Len ( ref place) => place. visit_with ( visitor) ,
2903
- Cast ( _, ref op, ty) => op. visit_with ( visitor) || ty. visit_with ( visitor) ,
2904
- BinaryOp ( _, ref rhs, ref lhs) | CheckedBinaryOp ( _, ref rhs, ref lhs) => {
2905
- rhs. visit_with ( visitor) || lhs. visit_with ( visitor)
2906
- }
2907
- UnaryOp ( _, ref val) => val. visit_with ( visitor) ,
2908
- Discriminant ( ref place) => place. visit_with ( visitor) ,
2909
- NullaryOp ( _, ty) => ty. visit_with ( visitor) ,
2910
- Aggregate ( ref kind, ref fields) => {
2911
- ( match * * kind {
2912
- AggregateKind :: Array ( ty) => ty. visit_with ( visitor) ,
2913
- AggregateKind :: Tuple => false ,
2914
- AggregateKind :: Adt ( _, _, substs, user_ty, _) => {
2915
- substs. visit_with ( visitor) || user_ty. visit_with ( visitor)
2916
- }
2917
- AggregateKind :: Closure ( _, substs) => substs. visit_with ( visitor) ,
2918
- AggregateKind :: Generator ( _, substs, _) => substs. visit_with ( visitor) ,
2919
- } ) || fields. visit_with ( visitor)
2920
- }
2921
- }
2922
- }
2923
- }
2924
-
2925
- impl < ' tcx > TypeFoldable < ' tcx > for Operand < ' tcx > {
2926
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2927
- match * self {
2928
- Operand :: Copy ( ref place) => Operand :: Copy ( place. fold_with ( folder) ) ,
2929
- Operand :: Move ( ref place) => Operand :: Move ( place. fold_with ( folder) ) ,
2930
- Operand :: Constant ( ref c) => Operand :: Constant ( c. fold_with ( folder) ) ,
2931
- }
2932
- }
2933
-
2934
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2935
- match * self {
2936
- Operand :: Copy ( ref place) | Operand :: Move ( ref place) => place. visit_with ( visitor) ,
2937
- Operand :: Constant ( ref c) => c. visit_with ( visitor) ,
2938
- }
2939
- }
2940
- }
2941
-
2942
- impl < ' tcx > TypeFoldable < ' tcx > for PlaceElem < ' tcx > {
2943
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2944
- use crate :: mir:: ProjectionElem :: * ;
2945
-
2946
- match * self {
2947
- Deref => Deref ,
2948
- Field ( f, ty) => Field ( f, ty. fold_with ( folder) ) ,
2949
- Index ( v) => Index ( v. fold_with ( folder) ) ,
2950
- Downcast ( symbol, variantidx) => Downcast ( symbol, variantidx) ,
2951
- ConstantIndex { offset, min_length, from_end } => {
2952
- ConstantIndex { offset, min_length, from_end }
2953
- }
2954
- Subslice { from, to, from_end } => Subslice { from, to, from_end } ,
2955
- }
2956
- }
2957
-
2958
- fn super_visit_with < Vs : TypeVisitor < ' tcx > > ( & self , visitor : & mut Vs ) -> bool {
2959
- use crate :: mir:: ProjectionElem :: * ;
2960
-
2961
- match self {
2962
- Field ( _, ty) => ty. visit_with ( visitor) ,
2963
- Index ( v) => v. visit_with ( visitor) ,
2964
- _ => false ,
2965
- }
2966
- }
2967
- }
2968
-
2969
- impl < ' tcx > TypeFoldable < ' tcx > for Field {
2970
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2971
- * self
2972
- }
2973
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2974
- false
2975
- }
2976
- }
2977
-
2978
- impl < ' tcx > TypeFoldable < ' tcx > for GeneratorSavedLocal {
2979
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2980
- * self
2981
- }
2982
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2983
- false
2984
- }
2985
- }
2986
-
2987
- impl < ' tcx , R : Idx , C : Idx > TypeFoldable < ' tcx > for BitMatrix < R , C > {
2988
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2989
- self . clone ( )
2990
- }
2991
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2992
- false
2993
- }
2994
- }
2995
-
2996
- impl < ' tcx > TypeFoldable < ' tcx > for Constant < ' tcx > {
2997
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2998
- Constant {
2999
- span : self . span ,
3000
- user_ty : self . user_ty . fold_with ( folder) ,
3001
- literal : self . literal . fold_with ( folder) ,
3002
- }
3003
- }
3004
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
3005
- self . literal . visit_with ( visitor)
3006
- }
3007
- }
0 commit comments