@@ -6,35 +6,33 @@ use std::fmt::Debug;
6
6
use std:: hash:: Hash ;
7
7
use std:: iter;
8
8
9
- use self :: SimplifiedType :: * ;
10
-
11
9
/// See `simplify_type`.
12
10
#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , TyEncodable , TyDecodable , HashStable ) ]
13
11
pub enum SimplifiedType {
14
- BoolSimplifiedType ,
15
- CharSimplifiedType ,
16
- IntSimplifiedType ( ty:: IntTy ) ,
17
- UintSimplifiedType ( ty:: UintTy ) ,
18
- FloatSimplifiedType ( ty:: FloatTy ) ,
19
- AdtSimplifiedType ( DefId ) ,
20
- ForeignSimplifiedType ( DefId ) ,
21
- StrSimplifiedType ,
22
- ArraySimplifiedType ,
23
- SliceSimplifiedType ,
24
- RefSimplifiedType ( Mutability ) ,
25
- PtrSimplifiedType ( Mutability ) ,
26
- NeverSimplifiedType ,
27
- TupleSimplifiedType ( usize ) ,
12
+ Bool ,
13
+ Char ,
14
+ Int ( ty:: IntTy ) ,
15
+ Uint ( ty:: UintTy ) ,
16
+ Float ( ty:: FloatTy ) ,
17
+ Adt ( DefId ) ,
18
+ Foreign ( DefId ) ,
19
+ Str ,
20
+ Array ,
21
+ Slice ,
22
+ Ref ( Mutability ) ,
23
+ Ptr ( Mutability ) ,
24
+ Never ,
25
+ Tuple ( usize ) ,
28
26
/// A trait object, all of whose components are markers
29
27
/// (e.g., `dyn Send + Sync`).
30
- MarkerTraitObjectSimplifiedType ,
31
- TraitSimplifiedType ( DefId ) ,
32
- ClosureSimplifiedType ( DefId ) ,
33
- GeneratorSimplifiedType ( DefId ) ,
34
- GeneratorWitnessSimplifiedType ( usize ) ,
35
- GeneratorWitnessMIRSimplifiedType ( DefId ) ,
36
- FunctionSimplifiedType ( usize ) ,
37
- PlaceholderSimplifiedType ,
28
+ MarkerTraitObject ,
29
+ Trait ( DefId ) ,
30
+ Closure ( DefId ) ,
31
+ Generator ( DefId ) ,
32
+ GeneratorWitness ( usize ) ,
33
+ GeneratorWitnessMIR ( DefId ) ,
34
+ Function ( usize ) ,
35
+ Placeholder ,
38
36
}
39
37
40
38
/// Generic parameters are pretty much just bound variables, e.g.
@@ -110,34 +108,36 @@ pub fn simplify_type<'tcx>(
110
108
treat_params : TreatParams ,
111
109
) -> Option < SimplifiedType > {
112
110
match * ty. kind ( ) {
113
- ty:: Bool => Some ( BoolSimplifiedType ) ,
114
- ty:: Char => Some ( CharSimplifiedType ) ,
115
- ty:: Int ( int_type) => Some ( IntSimplifiedType ( int_type) ) ,
116
- ty:: Uint ( uint_type) => Some ( UintSimplifiedType ( uint_type) ) ,
117
- ty:: Float ( float_type) => Some ( FloatSimplifiedType ( float_type) ) ,
118
- ty:: Adt ( def, _) => Some ( AdtSimplifiedType ( def. did ( ) ) ) ,
119
- ty:: Str => Some ( StrSimplifiedType ) ,
120
- ty:: Array ( ..) => Some ( ArraySimplifiedType ) ,
121
- ty:: Slice ( ..) => Some ( SliceSimplifiedType ) ,
122
- ty:: RawPtr ( ptr) => Some ( PtrSimplifiedType ( ptr. mutbl ) ) ,
111
+ ty:: Bool => Some ( SimplifiedType :: Bool ) ,
112
+ ty:: Char => Some ( SimplifiedType :: Char ) ,
113
+ ty:: Int ( int_type) => Some ( SimplifiedType :: Int ( int_type) ) ,
114
+ ty:: Uint ( uint_type) => Some ( SimplifiedType :: Uint ( uint_type) ) ,
115
+ ty:: Float ( float_type) => Some ( SimplifiedType :: Float ( float_type) ) ,
116
+ ty:: Adt ( def, _) => Some ( SimplifiedType :: Adt ( def. did ( ) ) ) ,
117
+ ty:: Str => Some ( SimplifiedType :: Str ) ,
118
+ ty:: Array ( ..) => Some ( SimplifiedType :: Array ) ,
119
+ ty:: Slice ( ..) => Some ( SimplifiedType :: Slice ) ,
120
+ ty:: RawPtr ( ptr) => Some ( SimplifiedType :: Ptr ( ptr. mutbl ) ) ,
123
121
ty:: Dynamic ( trait_info, ..) => match trait_info. principal_def_id ( ) {
124
122
Some ( principal_def_id) if !tcx. trait_is_auto ( principal_def_id) => {
125
- Some ( TraitSimplifiedType ( principal_def_id) )
123
+ Some ( SimplifiedType :: Trait ( principal_def_id) )
126
124
}
127
- _ => Some ( MarkerTraitObjectSimplifiedType ) ,
125
+ _ => Some ( SimplifiedType :: MarkerTraitObject ) ,
128
126
} ,
129
- ty:: Ref ( _, _, mutbl) => Some ( RefSimplifiedType ( mutbl) ) ,
130
- ty:: FnDef ( def_id, _) | ty:: Closure ( def_id, _) => Some ( ClosureSimplifiedType ( def_id) ) ,
131
- ty:: Generator ( def_id, _, _) => Some ( GeneratorSimplifiedType ( def_id) ) ,
132
- ty:: GeneratorWitness ( tys) => Some ( GeneratorWitnessSimplifiedType ( tys. skip_binder ( ) . len ( ) ) ) ,
133
- ty:: GeneratorWitnessMIR ( def_id, _) => Some ( GeneratorWitnessMIRSimplifiedType ( def_id) ) ,
134
- ty:: Never => Some ( NeverSimplifiedType ) ,
135
- ty:: Tuple ( tys) => Some ( TupleSimplifiedType ( tys. len ( ) ) ) ,
136
- ty:: FnPtr ( f) => Some ( FunctionSimplifiedType ( f. skip_binder ( ) . inputs ( ) . len ( ) ) ) ,
137
- ty:: Placeholder ( ..) => Some ( PlaceholderSimplifiedType ) ,
127
+ ty:: Ref ( _, _, mutbl) => Some ( SimplifiedType :: Ref ( mutbl) ) ,
128
+ ty:: FnDef ( def_id, _) | ty:: Closure ( def_id, _) => Some ( SimplifiedType :: Closure ( def_id) ) ,
129
+ ty:: Generator ( def_id, _, _) => Some ( SimplifiedType :: Generator ( def_id) ) ,
130
+ ty:: GeneratorWitness ( tys) => {
131
+ Some ( SimplifiedType :: GeneratorWitness ( tys. skip_binder ( ) . len ( ) ) )
132
+ }
133
+ ty:: GeneratorWitnessMIR ( def_id, _) => Some ( SimplifiedType :: GeneratorWitnessMIR ( def_id) ) ,
134
+ ty:: Never => Some ( SimplifiedType :: Never ) ,
135
+ ty:: Tuple ( tys) => Some ( SimplifiedType :: Tuple ( tys. len ( ) ) ) ,
136
+ ty:: FnPtr ( f) => Some ( SimplifiedType :: Function ( f. skip_binder ( ) . inputs ( ) . len ( ) ) ) ,
137
+ ty:: Placeholder ( ..) => Some ( SimplifiedType :: Placeholder ) ,
138
138
ty:: Param ( _) => match treat_params {
139
139
TreatParams :: ForLookup | TreatParams :: NextSolverLookup => {
140
- Some ( PlaceholderSimplifiedType )
140
+ Some ( SimplifiedType :: Placeholder )
141
141
}
142
142
TreatParams :: AsCandidateKey => None ,
143
143
} ,
@@ -147,24 +147,26 @@ pub fn simplify_type<'tcx>(
147
147
//
148
148
// We will have to be careful with lazy normalization here.
149
149
// FIXME(lazy_normalization): This is probably not right...
150
- TreatParams :: ForLookup if !ty. has_non_region_infer ( ) => Some ( PlaceholderSimplifiedType ) ,
151
- TreatParams :: NextSolverLookup => Some ( PlaceholderSimplifiedType ) ,
150
+ TreatParams :: ForLookup if !ty. has_non_region_infer ( ) => {
151
+ Some ( SimplifiedType :: Placeholder )
152
+ }
153
+ TreatParams :: NextSolverLookup => Some ( SimplifiedType :: Placeholder ) ,
152
154
TreatParams :: ForLookup | TreatParams :: AsCandidateKey => None ,
153
155
} ,
154
- ty:: Foreign ( def_id) => Some ( ForeignSimplifiedType ( def_id) ) ,
156
+ ty:: Foreign ( def_id) => Some ( SimplifiedType :: Foreign ( def_id) ) ,
155
157
ty:: Bound ( ..) | ty:: Infer ( _) | ty:: Error ( _) => None ,
156
158
}
157
159
}
158
160
159
161
impl SimplifiedType {
160
162
pub fn def ( self ) -> Option < DefId > {
161
163
match self {
162
- AdtSimplifiedType ( d)
163
- | ForeignSimplifiedType ( d)
164
- | TraitSimplifiedType ( d)
165
- | ClosureSimplifiedType ( d)
166
- | GeneratorSimplifiedType ( d)
167
- | GeneratorWitnessMIRSimplifiedType ( d) => Some ( d) ,
164
+ SimplifiedType :: Adt ( d)
165
+ | SimplifiedType :: Foreign ( d)
166
+ | SimplifiedType :: Trait ( d)
167
+ | SimplifiedType :: Closure ( d)
168
+ | SimplifiedType :: Generator ( d)
169
+ | SimplifiedType :: GeneratorWitnessMIR ( d) => Some ( d) ,
168
170
_ => None ,
169
171
}
170
172
}
0 commit comments