@@ -6,35 +6,33 @@ use std::fmt::Debug;
66use std:: hash:: Hash ;
77use std:: iter;
88
9- use self :: SimplifiedType :: * ;
10-
119/// See `simplify_type`.
1210#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash , TyEncodable , TyDecodable , HashStable ) ]
1311pub 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 ) ,
2826 /// A trait object, all of whose components are markers
2927 /// (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 ,
3836}
3937
4038/// Generic parameters are pretty much just bound variables, e.g.
@@ -64,6 +62,9 @@ pub enum TreatParams {
6462 /// correct mode for *lookup*, as during candidate selection.
6563 ///
6664 /// N.B. during deep rejection, this acts identically to `ForLookup`.
65+ ///
66+ /// FIXME(-Ztrait-solver=next): Remove this variant and cleanup
67+ /// the code.
6768 NextSolverLookup ,
6869}
6970
@@ -110,34 +111,36 @@ pub fn simplify_type<'tcx>(
110111 treat_params : TreatParams ,
111112) -> Option < SimplifiedType > {
112113 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 ) ) ,
123124 ty:: Dynamic ( trait_info, ..) => match trait_info. principal_def_id ( ) {
124125 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) )
126127 }
127- _ => Some ( MarkerTraitObjectSimplifiedType ) ,
128+ _ => Some ( SimplifiedType :: MarkerTraitObject ) ,
128129 } ,
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 ) ,
138141 ty:: Param ( _) => match treat_params {
139142 TreatParams :: ForLookup | TreatParams :: NextSolverLookup => {
140- Some ( PlaceholderSimplifiedType )
143+ Some ( SimplifiedType :: Placeholder )
141144 }
142145 TreatParams :: AsCandidateKey => None ,
143146 } ,
@@ -147,24 +150,26 @@ pub fn simplify_type<'tcx>(
147150 //
148151 // We will have to be careful with lazy normalization here.
149152 // 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 ) ,
152157 TreatParams :: ForLookup | TreatParams :: AsCandidateKey => None ,
153158 } ,
154- ty:: Foreign ( def_id) => Some ( ForeignSimplifiedType ( def_id) ) ,
159+ ty:: Foreign ( def_id) => Some ( SimplifiedType :: Foreign ( def_id) ) ,
155160 ty:: Bound ( ..) | ty:: Infer ( _) | ty:: Error ( _) => None ,
156161 }
157162}
158163
159164impl SimplifiedType {
160165 pub fn def ( self ) -> Option < DefId > {
161166 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) ,
168173 _ => None ,
169174 }
170175 }
0 commit comments