@@ -42,7 +42,7 @@ use arena::SyncDroplessArena;
4242use self :: combine:: CombineFields ;
4343use self :: higher_ranked:: HrMatchResult ;
4444use self :: region_constraints:: { RegionConstraintCollector , RegionSnapshot } ;
45- use self :: region_constraints:: { GenericKind , VerifyBound , RegionConstraintData , VarOrigins } ;
45+ use self :: region_constraints:: { GenericKind , VerifyBound , RegionConstraintData , VarInfos } ;
4646use self :: lexical_region_resolve:: LexicalRegionResolutions ;
4747use self :: outlives:: env:: OutlivesEnvironment ;
4848use self :: type_variable:: TypeVariableOrigin ;
@@ -183,6 +183,17 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
183183 // obligations within. This is expected to be done 'late enough'
184184 // that all type inference variables have been bound and so forth.
185185 pub region_obligations : RefCell < Vec < ( ast:: NodeId , RegionObligation < ' tcx > ) > > ,
186+
187+ /// What is the innermost universe we have created? Starts out as
188+ /// `UniverseIndex::root()` but grows from there as we enter
189+ /// universal quantifiers.
190+ ///
191+ /// NB: At present, we exclude the universal quantifiers on the
192+ /// item we are type-checking, and just consider those names as
193+ /// part of the root universe. So this would only get incremented
194+ /// when we enter into a higher-ranked (`for<..>`) type or trait
195+ /// bound.
196+ universe : Cell < ty:: UniverseIndex > ,
186197}
187198
188199/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
@@ -455,6 +466,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
455466 err_count_on_creation : tcx. sess . err_count ( ) ,
456467 in_snapshot : Cell :: new ( false ) ,
457468 region_obligations : RefCell :: new ( vec ! [ ] ) ,
469+ universe : Cell :: new ( ty:: UniverseIndex :: ROOT ) ,
458470 } ) )
459471 }
460472}
@@ -489,6 +501,7 @@ pub struct CombinedSnapshot<'a, 'tcx:'a> {
489501 float_snapshot : ut:: Snapshot < ut:: InPlace < ty:: FloatVid > > ,
490502 region_constraints_snapshot : RegionSnapshot ,
491503 region_obligations_snapshot : usize ,
504+ universe : ty:: UniverseIndex ,
492505 was_in_snapshot : bool ,
493506 _in_progress_tables : Option < Ref < ' a , ty:: TypeckTables < ' tcx > > > ,
494507}
@@ -618,6 +631,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
618631 float_snapshot : self . float_unification_table . borrow_mut ( ) . snapshot ( ) ,
619632 region_constraints_snapshot : self . borrow_region_constraints ( ) . start_snapshot ( ) ,
620633 region_obligations_snapshot : self . region_obligations . borrow ( ) . len ( ) ,
634+ universe : self . universe ( ) ,
621635 was_in_snapshot : in_snapshot,
622636 // Borrow tables "in progress" (i.e. during typeck)
623637 // to ban writes from within a snapshot to them.
@@ -635,10 +649,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
635649 float_snapshot,
636650 region_constraints_snapshot,
637651 region_obligations_snapshot,
652+ universe,
638653 was_in_snapshot,
639654 _in_progress_tables } = snapshot;
640655
641656 self . in_snapshot . set ( was_in_snapshot) ;
657+ self . universe . set ( universe) ;
642658
643659 self . projection_cache
644660 . borrow_mut ( )
@@ -667,6 +683,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
667683 float_snapshot,
668684 region_constraints_snapshot,
669685 region_obligations_snapshot : _,
686+ universe : _,
670687 was_in_snapshot,
671688 _in_progress_tables } = snapshot;
672689
@@ -811,7 +828,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
811828
812829 Some ( self . commit_if_ok ( |snapshot| {
813830 let ( ty:: SubtypePredicate { a_is_expected, a, b} , skol_map) =
814- self . skolemize_late_bound_regions ( predicate, snapshot ) ;
831+ self . skolemize_late_bound_regions ( predicate) ;
815832
816833 let cause_span = cause. span ;
817834 let ok = self . at ( cause, param_env) . sub_exp ( a_is_expected, a, b) ?;
@@ -828,7 +845,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
828845 {
829846 self . commit_if_ok ( |snapshot| {
830847 let ( ty:: OutlivesPredicate ( r_a, r_b) , skol_map) =
831- self . skolemize_late_bound_regions ( predicate, snapshot ) ;
848+ self . skolemize_late_bound_regions ( predicate) ;
832849 let origin =
833850 SubregionOrigin :: from_obligation_cause ( cause,
834851 || RelateRegionParamBound ( cause. span ) ) ;
@@ -841,7 +858,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
841858 pub fn next_ty_var_id ( & self , diverging : bool , origin : TypeVariableOrigin ) -> TyVid {
842859 self . type_variables
843860 . borrow_mut ( )
844- . new_var ( diverging, origin)
861+ . new_var ( self . universe ( ) , diverging, origin)
845862 }
846863
847864 pub fn next_ty_var ( & self , origin : TypeVariableOrigin ) -> Ty < ' tcx > {
@@ -872,12 +889,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
872889 /// during diagnostics / error-reporting.
873890 pub fn next_region_var ( & self , origin : RegionVariableOrigin )
874891 -> ty:: Region < ' tcx > {
875- self . tcx . mk_region ( ty:: ReVar ( self . borrow_region_constraints ( ) . new_region_var ( origin) ) )
892+ let region_var = self . borrow_region_constraints ( )
893+ . new_region_var ( self . universe ( ) , origin) ;
894+ self . tcx . mk_region ( ty:: ReVar ( region_var) )
876895 }
877896
878897 /// Number of region variables created so far.
879898 pub fn num_region_vars ( & self ) -> usize {
880- self . borrow_region_constraints ( ) . var_origins ( ) . len ( )
899+ self . borrow_region_constraints ( ) . num_region_vars ( )
881900 }
882901
883902 /// Just a convenient wrapper of `next_region_var` for using during NLL.
@@ -909,7 +928,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
909928 -> Ty < ' tcx > {
910929 let ty_var_id = self . type_variables
911930 . borrow_mut ( )
912- . new_var ( false ,
931+ . new_var ( self . universe ( ) ,
932+ false ,
913933 TypeVariableOrigin :: TypeParameterDefinition ( span, def. name ) ) ;
914934
915935 self . tcx . mk_var ( ty_var_id)
@@ -1004,12 +1024,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10041024 region_context,
10051025 region_map,
10061026 outlives_env. free_region_map ( ) ) ;
1007- let ( var_origins , data) = self . region_constraints . borrow_mut ( )
1027+ let ( var_infos , data) = self . region_constraints . borrow_mut ( )
10081028 . take ( )
10091029 . expect ( "regions already resolved" )
1010- . into_origins_and_data ( ) ;
1030+ . into_infos_and_data ( ) ;
10111031 let ( lexical_region_resolutions, errors) =
1012- lexical_region_resolve:: resolve ( region_rels, var_origins , data) ;
1032+ lexical_region_resolve:: resolve ( region_rels, var_infos , data) ;
10131033
10141034 let old_value = self . lexical_region_resolutions . replace ( Some ( lexical_region_resolutions) ) ;
10151035 assert ! ( old_value. is_none( ) ) ;
@@ -1057,13 +1077,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10571077 /// hence that `resolve_regions_and_report_errors` can never be
10581078 /// called. This is used only during NLL processing to "hand off" ownership
10591079 /// of the set of region vairables into the NLL region context.
1060- pub fn take_region_var_origins ( & self ) -> VarOrigins {
1061- let ( var_origins , data) = self . region_constraints . borrow_mut ( )
1080+ pub fn take_region_var_origins ( & self ) -> VarInfos {
1081+ let ( var_infos , data) = self . region_constraints . borrow_mut ( )
10621082 . take ( )
10631083 . expect ( "regions already resolved" )
1064- . into_origins_and_data ( ) ;
1084+ . into_infos_and_data ( ) ;
10651085 assert ! ( data. is_empty( ) ) ;
1066- var_origins
1086+ var_infos
10671087 }
10681088
10691089 pub fn ty_to_string ( & self , t : Ty < ' tcx > ) -> String {
@@ -1356,6 +1376,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13561376 self . evaluation_cache . clear ( ) ;
13571377 self . projection_cache . borrow_mut ( ) . clear ( ) ;
13581378 }
1379+
1380+ fn universe ( & self ) -> ty:: UniverseIndex {
1381+ self . universe . get ( )
1382+ }
13591383}
13601384
13611385impl < ' a , ' gcx , ' tcx > TypeTrace < ' tcx > {
0 commit comments