1
1
use super :: { InferCtxt , FixupError , FixupResult , Span , type_variable:: TypeVariableOrigin } ;
2
- use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable } ;
2
+ use crate :: mir:: interpret:: ConstValue ;
3
+ use crate :: ty:: { self , Ty , TyCtxt , TypeFoldable , InferConst } ;
3
4
use crate :: ty:: fold:: { TypeFolder , TypeVisitor } ;
4
5
5
6
///////////////////////////////////////////////////////////////////////////
6
7
// OPPORTUNISTIC TYPE RESOLVER
7
8
8
9
/// The opportunistic type resolver can be used at any time. It simply replaces
9
10
/// type variables that have been unified with the things they have
10
- /// been unified with (similar to `shallow_resolve `, but deep). This is
11
+ /// been unified with (similar to `shallow_resolve_type `, but deep). This is
11
12
/// useful for printing messages etc but also required at various
12
13
/// points for correctness.
13
14
pub struct OpportunisticTypeResolver < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
@@ -30,7 +31,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeResolver<'a, 'g
30
31
if !t. has_infer_types ( ) {
31
32
t // micro-optimize -- if there is nothing in this type that this fold affects...
32
33
} else {
33
- let t0 = self . infcx . shallow_resolve ( t) ;
34
+ let t0 = self . infcx . shallow_resolve_type ( t) ;
34
35
t0. super_fold_with ( self )
35
36
}
36
37
}
@@ -58,7 +59,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeAndRegionResolv
58
59
if !t. needs_infer ( ) {
59
60
t // micro-optimize -- if there is nothing in this type that this fold affects...
60
61
} else {
61
- let t0 = self . infcx . shallow_resolve ( t) ;
62
+ let t0 = self . infcx . shallow_resolve_type ( t) ;
62
63
t0. super_fold_with ( self )
63
64
}
64
65
}
@@ -72,6 +73,15 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeAndRegionResolv
72
73
r,
73
74
}
74
75
}
76
+
77
+ fn fold_const ( & mut self , ct : & ' tcx ty:: LazyConst < ' tcx > ) -> & ' tcx ty:: LazyConst < ' tcx > {
78
+ if !ct. needs_infer ( ) {
79
+ ct // micro-optimize -- if there is nothing in this const that this fold affects...
80
+ } else {
81
+ let c0 = self . infcx . shallow_resolve_const ( ct) ;
82
+ c0. super_fold_with ( self )
83
+ }
84
+ }
75
85
}
76
86
77
87
///////////////////////////////////////////////////////////////////////////
@@ -96,7 +106,7 @@ impl<'a, 'gcx, 'tcx> UnresolvedTypeFinder<'a, 'gcx, 'tcx> {
96
106
97
107
impl < ' a , ' gcx , ' tcx > TypeVisitor < ' tcx > for UnresolvedTypeFinder < ' a , ' gcx , ' tcx > {
98
108
fn visit_ty ( & mut self , t : Ty < ' tcx > ) -> bool {
99
- let t = self . infcx . shallow_resolve ( t) ;
109
+ let t = self . infcx . shallow_resolve_type ( t) ;
100
110
if t. has_infer_types ( ) {
101
111
if let ty:: Infer ( infer_ty) = t. sty {
102
112
// Since we called `shallow_resolve` above, this must
@@ -136,7 +146,7 @@ impl<'a, 'gcx, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'gcx, 'tcx>
136
146
/// their concrete results. If any variable cannot be replaced (never unified, etc)
137
147
/// then an `Err` result is returned.
138
148
pub fn fully_resolve < ' a , ' gcx , ' tcx , T > ( infcx : & InferCtxt < ' a , ' gcx , ' tcx > ,
139
- value : & T ) -> FixupResult < T >
149
+ value : & T ) -> FixupResult < ' tcx , T >
140
150
where T : TypeFoldable < ' tcx >
141
151
{
142
152
let mut full_resolver = FullTypeResolver { infcx : infcx, err : None } ;
@@ -151,7 +161,7 @@ pub fn fully_resolve<'a, 'gcx, 'tcx, T>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
151
161
// `err` field is not enforcable otherwise.
152
162
struct FullTypeResolver < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
153
163
infcx : & ' a InferCtxt < ' a , ' gcx , ' tcx > ,
154
- err : Option < FixupError > ,
164
+ err : Option < FixupError < ' tcx > > ,
155
165
}
156
166
157
167
impl < ' a , ' gcx , ' tcx > TypeFolder < ' gcx , ' tcx > for FullTypeResolver < ' a , ' gcx , ' tcx > {
@@ -165,7 +175,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx>
165
175
// ^ we need to have the `keep_local` check to un-default
166
176
// defaulted tuples.
167
177
} else {
168
- let t = self . infcx . shallow_resolve ( t) ;
178
+ let t = self . infcx . shallow_resolve_type ( t) ;
169
179
match t. sty {
170
180
ty:: Infer ( ty:: TyVar ( vid) ) => {
171
181
self . err = Some ( FixupError :: UnresolvedTy ( vid) ) ;
@@ -199,4 +209,30 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for FullTypeResolver<'a, 'gcx, 'tcx>
199
209
_ => r,
200
210
}
201
211
}
212
+
213
+ fn fold_const ( & mut self , c : & ' tcx ty:: LazyConst < ' tcx > ) -> & ' tcx ty:: LazyConst < ' tcx > {
214
+ if !c. needs_infer ( ) && !ty:: keep_local ( & c) {
215
+ c // micro-optimize -- if there is nothing in this const that this fold affects...
216
+ // ^ we need to have the `keep_local` check to un-default
217
+ // defaulted tuples.
218
+ } else {
219
+ let c = self . infcx . shallow_resolve_const ( c) ;
220
+ match c {
221
+ ty:: LazyConst :: Evaluated ( ty:: Const { val, .. } ) => {
222
+ match val {
223
+ ConstValue :: Infer ( InferConst :: Var ( vid) ) => {
224
+ self . err = Some ( FixupError :: UnresolvedConst ( * vid) ) ;
225
+ return self . tcx ( ) . types . ct_err ;
226
+ }
227
+ ConstValue :: Infer ( InferConst :: Fresh ( _) ) => {
228
+ bug ! ( "Unexpected const in full const resolver: {:?}" , c) ;
229
+ }
230
+ _ => { }
231
+ }
232
+ }
233
+ _ => { }
234
+ }
235
+ c. super_fold_with ( self )
236
+ }
237
+ }
202
238
}
0 commit comments