@@ -345,37 +345,61 @@ pub struct InferCtxt<'tcx> {
345
345
impl < ' tcx > ty:: InferCtxtLike for InferCtxt < ' tcx > {
346
346
type Interner = TyCtxt < ' tcx > ;
347
347
348
- fn universe_of_ty ( & self , ty : ty :: InferTy ) -> Option < ty :: UniverseIndex > {
349
- use InferTy :: * ;
350
- match ty {
351
- // FIXME(BoxyUwU): this is kind of jank and means that printing unresolved
352
- // ty infers will give you the universe of the var it resolved to not the universe
353
- // it actually had. It also means that if you have a `?0.1` and infer it to `u8` then
354
- // try to print out `?0.1` it will just print `?0`.
355
- TyVar ( ty_vid ) => match self . probe_ty_var ( ty_vid ) {
356
- Err ( universe ) => Some ( universe ) ,
357
- Ok ( _ ) => None ,
358
- } ,
359
- IntVar ( _ ) | FloatVar ( _ ) | FreshTy ( _ ) | FreshIntTy ( _ ) | FreshFloatTy ( _) => None ,
348
+ fn interner ( & self ) -> TyCtxt < ' tcx > {
349
+ self . tcx
350
+ }
351
+
352
+ fn universe_of_ty ( & self , vid : TyVid ) -> Option < ty :: UniverseIndex > {
353
+ // FIXME(BoxyUwU): this is kind of jank and means that printing unresolved
354
+ // ty infers will give you the universe of the var it resolved to not the universe
355
+ // it actually had. It also means that if you have a `?0.1` and infer it to `u8` then
356
+ // try to print out `?0.1` it will just print `?0`.
357
+ match self . probe_ty_var ( vid ) {
358
+ Err ( universe ) => Some ( universe ) ,
359
+ Ok ( _) => None ,
360
360
}
361
361
}
362
362
363
- fn universe_of_ct ( & self , ct : ty:: InferConst ) -> Option < ty:: UniverseIndex > {
364
- use ty:: InferConst :: * ;
365
- match ct {
366
- // Same issue as with `universe_of_ty`
367
- Var ( ct_vid) => match self . probe_const_var ( ct_vid) {
368
- Err ( universe) => Some ( universe) ,
369
- Ok ( _) => None ,
370
- } ,
371
- EffectVar ( _) => None ,
372
- Fresh ( _) => None ,
363
+ fn universe_of_ct ( & self , ct : ConstVid ) -> Option < ty:: UniverseIndex > {
364
+ // Same issue as with `universe_of_ty`
365
+ match self . probe_const_var ( ct) {
366
+ Err ( universe) => Some ( universe) ,
367
+ Ok ( _) => None ,
373
368
}
374
369
}
375
370
376
371
fn universe_of_lt ( & self , lt : ty:: RegionVid ) -> Option < ty:: UniverseIndex > {
377
372
Some ( self . universe_of_region_vid ( lt) )
378
373
}
374
+
375
+ fn root_ty_var ( & self , vid : TyVid ) -> TyVid {
376
+ self . root_var ( vid)
377
+ }
378
+
379
+ fn probe_ty_var ( & self , vid : TyVid ) -> Option < Ty < ' tcx > > {
380
+ self . probe_ty_var ( vid) . ok ( )
381
+ }
382
+
383
+ fn root_lt_var ( & self , vid : ty:: RegionVid ) -> ty:: RegionVid {
384
+ self . root_region_var ( vid)
385
+ }
386
+
387
+ fn probe_lt_var ( & self , vid : ty:: RegionVid ) -> Option < ty:: Region < ' tcx > > {
388
+ let re = self
389
+ . inner
390
+ . borrow_mut ( )
391
+ . unwrap_region_constraints ( )
392
+ . opportunistic_resolve_var ( self . tcx , vid) ;
393
+ if re. is_var ( ) { None } else { Some ( re) }
394
+ }
395
+
396
+ fn root_ct_var ( & self , vid : ConstVid ) -> ConstVid {
397
+ self . root_const_var ( vid)
398
+ }
399
+
400
+ fn probe_ct_var ( & self , vid : ConstVid ) -> Option < ty:: Const < ' tcx > > {
401
+ self . probe_const_var ( vid) . ok ( )
402
+ }
379
403
}
380
404
381
405
/// See the `error_reporting` module for more details.
@@ -1347,6 +1371,10 @@ impl<'tcx> InferCtxt<'tcx> {
1347
1371
self . inner . borrow_mut ( ) . type_variables ( ) . root_var ( var)
1348
1372
}
1349
1373
1374
+ pub fn root_region_var ( & self , var : ty:: RegionVid ) -> ty:: RegionVid {
1375
+ self . inner . borrow_mut ( ) . unwrap_region_constraints ( ) . root_var ( var)
1376
+ }
1377
+
1350
1378
pub fn root_const_var ( & self , var : ty:: ConstVid ) -> ty:: ConstVid {
1351
1379
self . inner . borrow_mut ( ) . const_unification_table ( ) . find ( var) . vid
1352
1380
}
0 commit comments