@@ -167,12 +167,20 @@ impl CanonicalizeRegionMode for CanonicalizeQueryResponse {
167167 ) -> ty:: Region < ' tcx > {
168168 match r {
169169 ty:: ReFree ( _) | ty:: ReEmpty | ty:: ReErased | ty:: ReStatic | ty:: ReEarlyBound ( ..) => r,
170- ty:: RePlaceholder ( placeholder) => {
171- let info = CanonicalVarInfo {
170+ ty:: RePlaceholder ( placeholder) => canonicalizer . canonical_var_for_region (
171+ CanonicalVarInfo {
172172 kind : CanonicalVarKind :: PlaceholderRegion ( * placeholder) ,
173- } ;
174- let cvar = canonicalizer. canonical_var ( info, r. into ( ) ) ;
175- canonicalizer. tcx . mk_region ( ty:: ReCanonical ( cvar. var ) )
173+ } ,
174+ r,
175+ ) ,
176+ ty:: ReVar ( vid) => {
177+ let universe = canonicalizer. region_var_universe ( * vid) ;
178+ canonicalizer. canonical_var_for_region (
179+ CanonicalVarInfo {
180+ kind : CanonicalVarKind :: Region ( universe) ,
181+ } ,
182+ r,
183+ )
176184 }
177185 _ => {
178186 // Other than `'static` or `'empty`, the query
@@ -259,7 +267,8 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for Canonicalizer<'cx, 'gcx, 'tcx>
259267 opportunistically resolved to {:?}",
260268 vid, r
261269 ) ;
262- self . canonical_var_for_region_in_root_universe ( r)
270+ self . canonicalize_region_mode
271+ . canonicalize_free_region ( self , r)
263272 }
264273
265274 ty:: ReStatic
@@ -483,9 +492,29 @@ impl<'cx, 'gcx, 'tcx> Canonicalizer<'cx, 'gcx, 'tcx> {
483492 & mut self ,
484493 r : ty:: Region < ' tcx > ,
485494 ) -> ty:: Region < ' tcx > {
486- let info = CanonicalVarInfo {
487- kind : CanonicalVarKind :: Region ( ty:: UniverseIndex :: ROOT ) ,
488- } ;
495+ self . canonical_var_for_region (
496+ CanonicalVarInfo {
497+ kind : CanonicalVarKind :: Region ( ty:: UniverseIndex :: ROOT ) ,
498+ } ,
499+ r,
500+ )
501+ }
502+
503+ /// Returns the universe in which `vid` is defined.
504+ fn region_var_universe ( & self , vid : ty:: RegionVid ) -> ty:: UniverseIndex {
505+ self . infcx
506+ . unwrap ( )
507+ . borrow_region_constraints ( )
508+ . var_universe ( vid)
509+ }
510+
511+ /// Create a canonical variable (with the given `info`)
512+ /// representing the region `r`; return a region referencing it.
513+ fn canonical_var_for_region (
514+ & mut self ,
515+ info : CanonicalVarInfo ,
516+ r : ty:: Region < ' tcx > ,
517+ ) -> ty:: Region < ' tcx > {
489518 let b = self . canonical_var ( info, r. into ( ) ) ;
490519 debug_assert_eq ! ( ty:: INNERMOST , b. level) ;
491520 self . tcx ( ) . mk_region ( ty:: ReCanonical ( b. var ) )
0 commit comments