@@ -25,9 +25,7 @@ use ty::ReStatic;
2525use ty:: { BrFresh , ReLateBound , ReSkolemized , ReVar } ;
2626
2727use std:: collections:: BTreeMap ;
28- use std:: fmt;
29- use std:: mem;
30- use std:: u32;
28+ use std:: { cmp, fmt, mem, u32} ;
3129
3230mod taint;
3331
@@ -233,6 +231,7 @@ type CombineMap<'tcx> = FxHashMap<TwoRegions<'tcx>, RegionVid>;
233231#[ derive( Debug , Clone , Copy ) ]
234232pub struct RegionVariableInfo {
235233 pub origin : RegionVariableOrigin ,
234+ pub universe : ty:: UniverseIndex ,
236235}
237236
238237pub struct RegionSnapshot {
@@ -438,9 +437,12 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
438437 }
439438 }
440439
441- pub fn new_region_var ( & mut self , origin : RegionVariableOrigin ) -> RegionVid {
440+ pub fn new_region_var ( & mut self ,
441+ universe : ty:: UniverseIndex ,
442+ origin : RegionVariableOrigin ) -> RegionVid {
442443 let vid = self . var_infos . push ( RegionVariableInfo {
443444 origin,
445+ universe,
444446 } ) ;
445447
446448 let u_vid = self . unification_table
@@ -457,6 +459,11 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
457459 return vid;
458460 }
459461
462+ /// Returns the universe for the given variable.
463+ pub fn var_universe ( & self , vid : RegionVid ) -> ty:: UniverseIndex {
464+ self . var_infos [ vid] . universe
465+ }
466+
460467 /// Returns the origin for the given variable.
461468 pub fn var_origin ( & self , vid : RegionVid ) -> RegionVariableOrigin {
462469 self . var_infos [ vid] . origin
@@ -812,7 +819,10 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
812819 if let Some ( & c) = self . combine_map ( t) . get ( & vars) {
813820 return tcx. mk_region ( ReVar ( c) ) ;
814821 }
815- let c = self . new_region_var ( MiscVariable ( origin. span ( ) ) ) ;
822+ let a_universe = self . universe ( a) ;
823+ let b_universe = self . universe ( b) ;
824+ let c_universe = cmp:: max ( a_universe, b_universe) ;
825+ let c = self . new_region_var ( c_universe, MiscVariable ( origin. span ( ) ) ) ;
816826 self . combine_map ( t) . insert ( vars, c) ;
817827 if self . in_snapshot ( ) {
818828 self . undo_log . push ( AddCombination ( t, vars) ) ;
@@ -828,6 +838,22 @@ impl<'tcx> RegionConstraintCollector<'tcx> {
828838 new_r
829839 }
830840
841+ fn universe ( & self , region : Region < ' tcx > ) -> ty:: UniverseIndex {
842+ match * region {
843+ ty:: ReScope ( ..) |
844+ ty:: ReStatic |
845+ ty:: ReEmpty |
846+ ty:: ReErased |
847+ ty:: ReFree ( ..) |
848+ ty:: ReEarlyBound ( ..) => ty:: UniverseIndex :: ROOT ,
849+ ty:: ReSkolemized ( universe, _) => universe,
850+ ty:: ReClosureBound ( vid) |
851+ ty:: ReVar ( vid) => self . var_universe ( vid) ,
852+ ty:: ReLateBound ( ..) =>
853+ bug ! ( "universe(): encountered bound region {:?}" , region) ,
854+ }
855+ }
856+
831857 pub fn vars_created_since_snapshot ( & self , mark : & RegionSnapshot ) -> Vec < RegionVid > {
832858 self . undo_log [ mark. length ..]
833859 . iter ( )
0 commit comments