@@ -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
@@ -2046,7 +2047,7 @@ pub enum Rvalue<'tcx> {
2046
2047
Use ( Operand < ' tcx > ) ,
2047
2048
2048
2049
/// [x; 32]
2049
- Repeat ( Operand < ' tcx > , u64 ) ,
2050
+ Repeat ( Operand < ' tcx > , & ' tcx ty :: Const < ' tcx > ) ,
2050
2051
2051
2052
/// &x or &mut x
2052
2053
Ref ( Region < ' tcx > , BorrowKind , Place < ' tcx > ) ,
@@ -2174,7 +2175,11 @@ impl<'tcx> Debug for Rvalue<'tcx> {
2174
2175
2175
2176
match * self {
2176
2177
Use ( ref place) => write ! ( fmt, "{:?}" , place) ,
2177
- Repeat ( ref a, ref b) => write ! ( fmt, "[{:?}; {:?}]" , a, b) ,
2178
+ Repeat ( ref a, ref b) => {
2179
+ write ! ( fmt, "[{:?}; " , a) ?;
2180
+ pretty_print_const ( b, fmt, false ) ?;
2181
+ write ! ( fmt, "]" )
2182
+ }
2178
2183
Len ( ref a) => write ! ( fmt, "Len({:?})" , a) ,
2179
2184
Cast ( ref kind, ref place, ref ty) => {
2180
2185
write ! ( fmt, "{:?} as {:?} ({:?})" , place, ty, kind)
@@ -2542,18 +2547,26 @@ impl<'tcx> Debug for Constant<'tcx> {
2542
2547
2543
2548
impl < ' tcx > Display for Constant < ' tcx > {
2544
2549
fn fmt ( & self , fmt : & mut Formatter < ' _ > ) -> fmt:: Result {
2545
- use crate :: ty:: print:: PrettyPrinter ;
2546
2550
write ! ( fmt, "const " ) ?;
2547
- ty:: tls:: with ( |tcx| {
2548
- let literal = tcx. lift ( & self . literal ) . unwrap ( ) ;
2549
- let mut cx = FmtPrinter :: new ( tcx, fmt, Namespace :: ValueNS ) ;
2550
- cx. print_alloc_ids = true ;
2551
- cx. pretty_print_const ( literal, true ) ?;
2552
- Ok ( ( ) )
2553
- } )
2551
+ pretty_print_const ( self . literal , fmt, true )
2554
2552
}
2555
2553
}
2556
2554
2555
+ fn pretty_print_const (
2556
+ c : & ty:: Const < ' tcx > ,
2557
+ fmt : & mut Formatter < ' _ > ,
2558
+ print_types : bool ,
2559
+ ) -> fmt:: Result {
2560
+ use crate :: ty:: print:: PrettyPrinter ;
2561
+ ty:: tls:: with ( |tcx| {
2562
+ let literal = tcx. lift ( & c) . unwrap ( ) ;
2563
+ let mut cx = FmtPrinter :: new ( tcx, fmt, Namespace :: ValueNS ) ;
2564
+ cx. print_alloc_ids = true ;
2565
+ cx. pretty_print_const ( literal, print_types) ?;
2566
+ Ok ( ( ) )
2567
+ } )
2568
+ }
2569
+
2557
2570
impl < ' tcx > graph:: DirectedGraph for Body < ' tcx > {
2558
2571
type Node = BasicBlock ;
2559
2572
}
@@ -2651,325 +2664,3 @@ impl Location {
2651
2664
}
2652
2665
}
2653
2666
}
2654
-
2655
- /*
2656
- * `TypeFoldable` implementations for MIR types
2657
- */
2658
-
2659
- CloneTypeFoldableAndLiftImpls ! {
2660
- BlockTailInfo ,
2661
- MirPhase ,
2662
- SourceInfo ,
2663
- FakeReadCause ,
2664
- RetagKind ,
2665
- SourceScope ,
2666
- SourceScopeData ,
2667
- SourceScopeLocalData ,
2668
- UserTypeAnnotationIndex ,
2669
- }
2670
-
2671
- impl < ' tcx > TypeFoldable < ' tcx > for Terminator < ' tcx > {
2672
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2673
- use crate :: mir:: TerminatorKind :: * ;
2674
-
2675
- let kind = match self . kind {
2676
- Goto { target } => Goto { target } ,
2677
- SwitchInt { ref discr, switch_ty, ref values, ref targets } => SwitchInt {
2678
- discr : discr. fold_with ( folder) ,
2679
- switch_ty : switch_ty. fold_with ( folder) ,
2680
- values : values. clone ( ) ,
2681
- targets : targets. clone ( ) ,
2682
- } ,
2683
- Drop { ref location, target, unwind } => {
2684
- Drop { location : location. fold_with ( folder) , target, unwind }
2685
- }
2686
- DropAndReplace { ref location, ref value, target, unwind } => DropAndReplace {
2687
- location : location. fold_with ( folder) ,
2688
- value : value. fold_with ( folder) ,
2689
- target,
2690
- unwind,
2691
- } ,
2692
- Yield { ref value, resume, ref resume_arg, drop } => Yield {
2693
- value : value. fold_with ( folder) ,
2694
- resume,
2695
- resume_arg : resume_arg. fold_with ( folder) ,
2696
- drop,
2697
- } ,
2698
- Call { ref func, ref args, ref destination, cleanup, from_hir_call } => {
2699
- let dest =
2700
- destination. as_ref ( ) . map ( |& ( ref loc, dest) | ( loc. fold_with ( folder) , dest) ) ;
2701
-
2702
- Call {
2703
- func : func. fold_with ( folder) ,
2704
- args : args. fold_with ( folder) ,
2705
- destination : dest,
2706
- cleanup,
2707
- from_hir_call,
2708
- }
2709
- }
2710
- Assert { ref cond, expected, ref msg, target, cleanup } => {
2711
- use AssertKind :: * ;
2712
- let msg = match msg {
2713
- BoundsCheck { ref len, ref index } => {
2714
- BoundsCheck { len : len. fold_with ( folder) , index : index. fold_with ( folder) }
2715
- }
2716
- Overflow ( _)
2717
- | OverflowNeg
2718
- | DivisionByZero
2719
- | RemainderByZero
2720
- | ResumedAfterReturn ( _)
2721
- | ResumedAfterPanic ( _) => msg. clone ( ) ,
2722
- } ;
2723
- Assert { cond : cond. fold_with ( folder) , expected, msg, target, cleanup }
2724
- }
2725
- GeneratorDrop => GeneratorDrop ,
2726
- Resume => Resume ,
2727
- Abort => Abort ,
2728
- Return => Return ,
2729
- Unreachable => Unreachable ,
2730
- FalseEdges { real_target, imaginary_target } => {
2731
- FalseEdges { real_target, imaginary_target }
2732
- }
2733
- FalseUnwind { real_target, unwind } => FalseUnwind { real_target, unwind } ,
2734
- } ;
2735
- Terminator { source_info : self . source_info , kind }
2736
- }
2737
-
2738
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2739
- use crate :: mir:: TerminatorKind :: * ;
2740
-
2741
- match self . kind {
2742
- SwitchInt { ref discr, switch_ty, .. } => {
2743
- discr. visit_with ( visitor) || switch_ty. visit_with ( visitor)
2744
- }
2745
- Drop { ref location, .. } => location. visit_with ( visitor) ,
2746
- DropAndReplace { ref location, ref value, .. } => {
2747
- location. visit_with ( visitor) || value. visit_with ( visitor)
2748
- }
2749
- Yield { ref value, .. } => value. visit_with ( visitor) ,
2750
- Call { ref func, ref args, ref destination, .. } => {
2751
- let dest = if let Some ( ( ref loc, _) ) = * destination {
2752
- loc. visit_with ( visitor)
2753
- } else {
2754
- false
2755
- } ;
2756
- dest || func. visit_with ( visitor) || args. visit_with ( visitor)
2757
- }
2758
- Assert { ref cond, ref msg, .. } => {
2759
- if cond. visit_with ( visitor) {
2760
- use AssertKind :: * ;
2761
- match msg {
2762
- BoundsCheck { ref len, ref index } => {
2763
- len. visit_with ( visitor) || index. visit_with ( visitor)
2764
- }
2765
- Overflow ( _)
2766
- | OverflowNeg
2767
- | DivisionByZero
2768
- | RemainderByZero
2769
- | ResumedAfterReturn ( _)
2770
- | ResumedAfterPanic ( _) => false ,
2771
- }
2772
- } else {
2773
- false
2774
- }
2775
- }
2776
- Goto { .. }
2777
- | Resume
2778
- | Abort
2779
- | Return
2780
- | GeneratorDrop
2781
- | Unreachable
2782
- | FalseEdges { .. }
2783
- | FalseUnwind { .. } => false ,
2784
- }
2785
- }
2786
- }
2787
-
2788
- impl < ' tcx > TypeFoldable < ' tcx > for GeneratorKind {
2789
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2790
- * self
2791
- }
2792
-
2793
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2794
- false
2795
- }
2796
- }
2797
-
2798
- impl < ' tcx > TypeFoldable < ' tcx > for Place < ' tcx > {
2799
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2800
- Place { local : self . local . fold_with ( folder) , projection : self . projection . fold_with ( folder) }
2801
- }
2802
-
2803
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2804
- self . local . visit_with ( visitor) || self . projection . visit_with ( visitor)
2805
- }
2806
- }
2807
-
2808
- impl < ' tcx > TypeFoldable < ' tcx > for & ' tcx ty:: List < PlaceElem < ' tcx > > {
2809
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2810
- let v = self . iter ( ) . map ( |t| t. fold_with ( folder) ) . collect :: < Vec < _ > > ( ) ;
2811
- folder. tcx ( ) . intern_place_elems ( & v)
2812
- }
2813
-
2814
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2815
- self . iter ( ) . any ( |t| t. visit_with ( visitor) )
2816
- }
2817
- }
2818
-
2819
- impl < ' tcx > TypeFoldable < ' tcx > for Rvalue < ' tcx > {
2820
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2821
- use crate :: mir:: Rvalue :: * ;
2822
- match * self {
2823
- Use ( ref op) => Use ( op. fold_with ( folder) ) ,
2824
- Repeat ( ref op, len) => Repeat ( op. fold_with ( folder) , len) ,
2825
- Ref ( region, bk, ref place) => {
2826
- Ref ( region. fold_with ( folder) , bk, place. fold_with ( folder) )
2827
- }
2828
- AddressOf ( mutability, ref place) => AddressOf ( mutability, place. fold_with ( folder) ) ,
2829
- Len ( ref place) => Len ( place. fold_with ( folder) ) ,
2830
- Cast ( kind, ref op, ty) => Cast ( kind, op. fold_with ( folder) , ty. fold_with ( folder) ) ,
2831
- BinaryOp ( op, ref rhs, ref lhs) => {
2832
- BinaryOp ( op, rhs. fold_with ( folder) , lhs. fold_with ( folder) )
2833
- }
2834
- CheckedBinaryOp ( op, ref rhs, ref lhs) => {
2835
- CheckedBinaryOp ( op, rhs. fold_with ( folder) , lhs. fold_with ( folder) )
2836
- }
2837
- UnaryOp ( op, ref val) => UnaryOp ( op, val. fold_with ( folder) ) ,
2838
- Discriminant ( ref place) => Discriminant ( place. fold_with ( folder) ) ,
2839
- NullaryOp ( op, ty) => NullaryOp ( op, ty. fold_with ( folder) ) ,
2840
- Aggregate ( ref kind, ref fields) => {
2841
- let kind = box match * * kind {
2842
- AggregateKind :: Array ( ty) => AggregateKind :: Array ( ty. fold_with ( folder) ) ,
2843
- AggregateKind :: Tuple => AggregateKind :: Tuple ,
2844
- AggregateKind :: Adt ( def, v, substs, user_ty, n) => AggregateKind :: Adt (
2845
- def,
2846
- v,
2847
- substs. fold_with ( folder) ,
2848
- user_ty. fold_with ( folder) ,
2849
- n,
2850
- ) ,
2851
- AggregateKind :: Closure ( id, substs) => {
2852
- AggregateKind :: Closure ( id, substs. fold_with ( folder) )
2853
- }
2854
- AggregateKind :: Generator ( id, substs, movablity) => {
2855
- AggregateKind :: Generator ( id, substs. fold_with ( folder) , movablity)
2856
- }
2857
- } ;
2858
- Aggregate ( kind, fields. fold_with ( folder) )
2859
- }
2860
- }
2861
- }
2862
-
2863
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2864
- use crate :: mir:: Rvalue :: * ;
2865
- match * self {
2866
- Use ( ref op) => op. visit_with ( visitor) ,
2867
- Repeat ( ref op, _) => op. visit_with ( visitor) ,
2868
- Ref ( region, _, ref place) => region. visit_with ( visitor) || place. visit_with ( visitor) ,
2869
- AddressOf ( _, ref place) => place. visit_with ( visitor) ,
2870
- Len ( ref place) => place. visit_with ( visitor) ,
2871
- Cast ( _, ref op, ty) => op. visit_with ( visitor) || ty. visit_with ( visitor) ,
2872
- BinaryOp ( _, ref rhs, ref lhs) | CheckedBinaryOp ( _, ref rhs, ref lhs) => {
2873
- rhs. visit_with ( visitor) || lhs. visit_with ( visitor)
2874
- }
2875
- UnaryOp ( _, ref val) => val. visit_with ( visitor) ,
2876
- Discriminant ( ref place) => place. visit_with ( visitor) ,
2877
- NullaryOp ( _, ty) => ty. visit_with ( visitor) ,
2878
- Aggregate ( ref kind, ref fields) => {
2879
- ( match * * kind {
2880
- AggregateKind :: Array ( ty) => ty. visit_with ( visitor) ,
2881
- AggregateKind :: Tuple => false ,
2882
- AggregateKind :: Adt ( _, _, substs, user_ty, _) => {
2883
- substs. visit_with ( visitor) || user_ty. visit_with ( visitor)
2884
- }
2885
- AggregateKind :: Closure ( _, substs) => substs. visit_with ( visitor) ,
2886
- AggregateKind :: Generator ( _, substs, _) => substs. visit_with ( visitor) ,
2887
- } ) || fields. visit_with ( visitor)
2888
- }
2889
- }
2890
- }
2891
- }
2892
-
2893
- impl < ' tcx > TypeFoldable < ' tcx > for Operand < ' tcx > {
2894
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2895
- match * self {
2896
- Operand :: Copy ( ref place) => Operand :: Copy ( place. fold_with ( folder) ) ,
2897
- Operand :: Move ( ref place) => Operand :: Move ( place. fold_with ( folder) ) ,
2898
- Operand :: Constant ( ref c) => Operand :: Constant ( c. fold_with ( folder) ) ,
2899
- }
2900
- }
2901
-
2902
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2903
- match * self {
2904
- Operand :: Copy ( ref place) | Operand :: Move ( ref place) => place. visit_with ( visitor) ,
2905
- Operand :: Constant ( ref c) => c. visit_with ( visitor) ,
2906
- }
2907
- }
2908
- }
2909
-
2910
- impl < ' tcx > TypeFoldable < ' tcx > for PlaceElem < ' tcx > {
2911
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2912
- use crate :: mir:: ProjectionElem :: * ;
2913
-
2914
- match * self {
2915
- Deref => Deref ,
2916
- Field ( f, ty) => Field ( f, ty. fold_with ( folder) ) ,
2917
- Index ( v) => Index ( v. fold_with ( folder) ) ,
2918
- Downcast ( symbol, variantidx) => Downcast ( symbol, variantidx) ,
2919
- ConstantIndex { offset, min_length, from_end } => {
2920
- ConstantIndex { offset, min_length, from_end }
2921
- }
2922
- Subslice { from, to, from_end } => Subslice { from, to, from_end } ,
2923
- }
2924
- }
2925
-
2926
- fn super_visit_with < Vs : TypeVisitor < ' tcx > > ( & self , visitor : & mut Vs ) -> bool {
2927
- use crate :: mir:: ProjectionElem :: * ;
2928
-
2929
- match self {
2930
- Field ( _, ty) => ty. visit_with ( visitor) ,
2931
- Index ( v) => v. visit_with ( visitor) ,
2932
- _ => false ,
2933
- }
2934
- }
2935
- }
2936
-
2937
- impl < ' tcx > TypeFoldable < ' tcx > for Field {
2938
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2939
- * self
2940
- }
2941
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2942
- false
2943
- }
2944
- }
2945
-
2946
- impl < ' tcx > TypeFoldable < ' tcx > for GeneratorSavedLocal {
2947
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2948
- * self
2949
- }
2950
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2951
- false
2952
- }
2953
- }
2954
-
2955
- impl < ' tcx , R : Idx , C : Idx > TypeFoldable < ' tcx > for BitMatrix < R , C > {
2956
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , _: & mut F ) -> Self {
2957
- self . clone ( )
2958
- }
2959
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , _: & mut V ) -> bool {
2960
- false
2961
- }
2962
- }
2963
-
2964
- impl < ' tcx > TypeFoldable < ' tcx > for Constant < ' tcx > {
2965
- fn super_fold_with < F : TypeFolder < ' tcx > > ( & self , folder : & mut F ) -> Self {
2966
- Constant {
2967
- span : self . span ,
2968
- user_ty : self . user_ty . fold_with ( folder) ,
2969
- literal : self . literal . fold_with ( folder) ,
2970
- }
2971
- }
2972
- fn super_visit_with < V : TypeVisitor < ' tcx > > ( & self , visitor : & mut V ) -> bool {
2973
- self . literal . visit_with ( visitor)
2974
- }
2975
- }
0 commit comments