@@ -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.
@@ -64,6 +62,9 @@ pub enum TreatParams {
64
62
/// correct mode for *lookup*, as during candidate selection.
65
63
///
66
64
/// N.B. during deep rejection, this acts identically to `ForLookup`.
65
+ ///
66
+ /// FIXME(-Ztrait-solver=next): Remove this variant and cleanup
67
+ /// the code.
67
68
NextSolverLookup ,
68
69
}
69
70
@@ -110,34 +111,36 @@ pub fn simplify_type<'tcx>(
110
111
treat_params : TreatParams ,
111
112
) -> Option < SimplifiedType > {
112
113
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 ) ) ,
114
+ ty:: Bool => Some ( SimplifiedType :: Bool ) ,
115
+ ty:: Char => Some ( SimplifiedType :: Char ) ,
116
+ ty:: Int ( int_type) => Some ( SimplifiedType :: Int ( int_type) ) ,
117
+ ty:: Uint ( uint_type) => Some ( SimplifiedType :: Uint ( uint_type) ) ,
118
+ ty:: Float ( float_type) => Some ( SimplifiedType :: Float ( float_type) ) ,
119
+ ty:: Adt ( def, _) => Some ( SimplifiedType :: Adt ( def. did ( ) ) ) ,
120
+ ty:: Str => Some ( SimplifiedType :: Str ) ,
121
+ ty:: Array ( ..) => Some ( SimplifiedType :: Array ) ,
122
+ ty:: Slice ( ..) => Some ( SimplifiedType :: Slice ) ,
123
+ ty:: RawPtr ( ptr) => Some ( SimplifiedType :: Ptr ( ptr. mutbl ) ) ,
123
124
ty:: Dynamic ( trait_info, ..) => match trait_info. principal_def_id ( ) {
124
125
Some ( principal_def_id) if !tcx. trait_is_auto ( principal_def_id) => {
125
- Some ( TraitSimplifiedType ( principal_def_id) )
126
+ Some ( SimplifiedType :: Trait ( principal_def_id) )
126
127
}
127
- _ => Some ( MarkerTraitObjectSimplifiedType ) ,
128
+ _ => Some ( SimplifiedType :: MarkerTraitObject ) ,
128
129
} ,
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 ) ,
130
+ ty:: Ref ( _, _, mutbl) => Some ( SimplifiedType :: Ref ( mutbl) ) ,
131
+ ty:: FnDef ( def_id, _) | ty:: Closure ( def_id, _) => Some ( SimplifiedType :: Closure ( def_id) ) ,
132
+ ty:: Generator ( def_id, _, _) => Some ( SimplifiedType :: Generator ( def_id) ) ,
133
+ ty:: GeneratorWitness ( tys) => {
134
+ Some ( SimplifiedType :: GeneratorWitness ( tys. skip_binder ( ) . len ( ) ) )
135
+ }
136
+ ty:: GeneratorWitnessMIR ( def_id, _) => Some ( SimplifiedType :: GeneratorWitnessMIR ( def_id) ) ,
137
+ ty:: Never => Some ( SimplifiedType :: Never ) ,
138
+ ty:: Tuple ( tys) => Some ( SimplifiedType :: Tuple ( tys. len ( ) ) ) ,
139
+ ty:: FnPtr ( f) => Some ( SimplifiedType :: Function ( f. skip_binder ( ) . inputs ( ) . len ( ) ) ) ,
140
+ ty:: Placeholder ( ..) => Some ( SimplifiedType :: Placeholder ) ,
138
141
ty:: Param ( _) => match treat_params {
139
142
TreatParams :: ForLookup | TreatParams :: NextSolverLookup => {
140
- Some ( PlaceholderSimplifiedType )
143
+ Some ( SimplifiedType :: Placeholder )
141
144
}
142
145
TreatParams :: AsCandidateKey => None ,
143
146
} ,
@@ -147,24 +150,26 @@ pub fn simplify_type<'tcx>(
147
150
//
148
151
// We will have to be careful with lazy normalization here.
149
152
// FIXME(lazy_normalization): This is probably not right...
150
- TreatParams :: ForLookup if !ty. has_non_region_infer ( ) => Some ( PlaceholderSimplifiedType ) ,
151
- TreatParams :: NextSolverLookup => Some ( PlaceholderSimplifiedType ) ,
153
+ TreatParams :: ForLookup if !ty. has_non_region_infer ( ) => {
154
+ Some ( SimplifiedType :: Placeholder )
155
+ }
156
+ TreatParams :: NextSolverLookup => Some ( SimplifiedType :: Placeholder ) ,
152
157
TreatParams :: ForLookup | TreatParams :: AsCandidateKey => None ,
153
158
} ,
154
- ty:: Foreign ( def_id) => Some ( ForeignSimplifiedType ( def_id) ) ,
159
+ ty:: Foreign ( def_id) => Some ( SimplifiedType :: Foreign ( def_id) ) ,
155
160
ty:: Bound ( ..) | ty:: Infer ( _) | ty:: Error ( _) => None ,
156
161
}
157
162
}
158
163
159
164
impl SimplifiedType {
160
165
pub fn def ( self ) -> Option < DefId > {
161
166
match self {
162
- AdtSimplifiedType ( d)
163
- | ForeignSimplifiedType ( d)
164
- | TraitSimplifiedType ( d)
165
- | ClosureSimplifiedType ( d)
166
- | GeneratorSimplifiedType ( d)
167
- | GeneratorWitnessMIRSimplifiedType ( d) => Some ( d) ,
167
+ SimplifiedType :: Adt ( d)
168
+ | SimplifiedType :: Foreign ( d)
169
+ | SimplifiedType :: Trait ( d)
170
+ | SimplifiedType :: Closure ( d)
171
+ | SimplifiedType :: Generator ( d)
172
+ | SimplifiedType :: GeneratorWitnessMIR ( d) => Some ( d) ,
168
173
_ => None ,
169
174
}
170
175
}
0 commit comments