@@ -260,3 +260,85 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
260
260
}
261
261
}
262
262
}
263
+
264
+ ///////////////////////////////////////////////////////////////////////////
265
+ // EAGER RESOLUTION
266
+
267
+ /// Resolves ty, region, and const vars to their inferred values or their root vars.
268
+ pub struct EagerResolver < ' a , ' tcx > {
269
+ infcx : & ' a InferCtxt < ' tcx > ,
270
+ }
271
+
272
+ impl < ' a , ' tcx > EagerResolver < ' a , ' tcx > {
273
+ pub fn new ( infcx : & ' a InferCtxt < ' tcx > ) -> Self {
274
+ EagerResolver { infcx }
275
+ }
276
+ }
277
+
278
+ impl < ' tcx > TypeFolder < TyCtxt < ' tcx > > for EagerResolver < ' _ , ' tcx > {
279
+ fn interner ( & self ) -> TyCtxt < ' tcx > {
280
+ self . infcx . tcx
281
+ }
282
+
283
+ fn fold_ty ( & mut self , t : Ty < ' tcx > ) -> Ty < ' tcx > {
284
+ match * t. kind ( ) {
285
+ ty:: Infer ( ty:: TyVar ( vid) ) => match self . infcx . probe_ty_var ( vid) {
286
+ Ok ( t) => t. fold_with ( self ) ,
287
+ Err ( _) => Ty :: new_var ( self . infcx . tcx , self . infcx . root_var ( vid) ) ,
288
+ } ,
289
+ ty:: Infer ( ty:: IntVar ( vid) ) => self . infcx . opportunistic_resolve_int_var ( vid) ,
290
+ ty:: Infer ( ty:: FloatVar ( vid) ) => self . infcx . opportunistic_resolve_float_var ( vid) ,
291
+ _ => {
292
+ if t. has_infer ( ) {
293
+ t. super_fold_with ( self )
294
+ } else {
295
+ t
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ fn fold_region ( & mut self , r : ty:: Region < ' tcx > ) -> ty:: Region < ' tcx > {
302
+ match * r {
303
+ ty:: ReVar ( vid) => self
304
+ . infcx
305
+ . inner
306
+ . borrow_mut ( )
307
+ . unwrap_region_constraints ( )
308
+ . opportunistic_resolve_var ( self . infcx . tcx , vid) ,
309
+ _ => r,
310
+ }
311
+ }
312
+
313
+ fn fold_const ( & mut self , c : ty:: Const < ' tcx > ) -> ty:: Const < ' tcx > {
314
+ match c. kind ( ) {
315
+ ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( vid) ) => {
316
+ // FIXME: we need to fold the ty too, I think.
317
+ match self . infcx . probe_const_var ( vid) {
318
+ Ok ( c) => c. fold_with ( self ) ,
319
+ Err ( _) => {
320
+ ty:: Const :: new_var ( self . infcx . tcx , self . infcx . root_const_var ( vid) , c. ty ( ) )
321
+ }
322
+ }
323
+ }
324
+ ty:: ConstKind :: Infer ( ty:: InferConst :: EffectVar ( vid) ) => {
325
+ debug_assert_eq ! ( c. ty( ) , self . infcx. tcx. types. bool ) ;
326
+ match self . infcx . probe_effect_var ( vid) {
327
+ Some ( c) => c. as_const ( self . infcx . tcx ) ,
328
+ None => ty:: Const :: new_infer (
329
+ self . infcx . tcx ,
330
+ ty:: InferConst :: EffectVar ( self . infcx . root_effect_var ( vid) ) ,
331
+ self . infcx . tcx . types . bool ,
332
+ ) ,
333
+ }
334
+ }
335
+ _ => {
336
+ if c. has_infer ( ) {
337
+ c. super_fold_with ( self )
338
+ } else {
339
+ c
340
+ }
341
+ }
342
+ }
343
+ }
344
+ }
0 commit comments