@@ -42,7 +42,7 @@ use arena::SyncDroplessArena;
42
42
use self :: combine:: CombineFields ;
43
43
use self :: higher_ranked:: HrMatchResult ;
44
44
use self :: region_constraints:: { RegionConstraintCollector , RegionSnapshot } ;
45
- use self :: region_constraints:: { GenericKind , VerifyBound , RegionConstraintData , VarOrigins } ;
45
+ use self :: region_constraints:: { GenericKind , VerifyBound , RegionConstraintData , VarInfos } ;
46
46
use self :: lexical_region_resolve:: LexicalRegionResolutions ;
47
47
use self :: outlives:: env:: OutlivesEnvironment ;
48
48
use self :: type_variable:: TypeVariableOrigin ;
@@ -183,6 +183,17 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
183
183
// obligations within. This is expected to be done 'late enough'
184
184
// that all type inference variables have been bound and so forth.
185
185
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 > ,
186
197
}
187
198
188
199
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
@@ -455,6 +466,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
455
466
err_count_on_creation : tcx. sess . err_count ( ) ,
456
467
in_snapshot : Cell :: new ( false ) ,
457
468
region_obligations : RefCell :: new ( vec ! [ ] ) ,
469
+ universe : Cell :: new ( ty:: UniverseIndex :: ROOT ) ,
458
470
} ) )
459
471
}
460
472
}
@@ -489,6 +501,7 @@ pub struct CombinedSnapshot<'a, 'tcx:'a> {
489
501
float_snapshot : ut:: Snapshot < ut:: InPlace < ty:: FloatVid > > ,
490
502
region_constraints_snapshot : RegionSnapshot ,
491
503
region_obligations_snapshot : usize ,
504
+ universe : ty:: UniverseIndex ,
492
505
was_in_snapshot : bool ,
493
506
_in_progress_tables : Option < Ref < ' a , ty:: TypeckTables < ' tcx > > > ,
494
507
}
@@ -618,6 +631,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
618
631
float_snapshot : self . float_unification_table . borrow_mut ( ) . snapshot ( ) ,
619
632
region_constraints_snapshot : self . borrow_region_constraints ( ) . start_snapshot ( ) ,
620
633
region_obligations_snapshot : self . region_obligations . borrow ( ) . len ( ) ,
634
+ universe : self . universe ( ) ,
621
635
was_in_snapshot : in_snapshot,
622
636
// Borrow tables "in progress" (i.e. during typeck)
623
637
// to ban writes from within a snapshot to them.
@@ -635,10 +649,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
635
649
float_snapshot,
636
650
region_constraints_snapshot,
637
651
region_obligations_snapshot,
652
+ universe,
638
653
was_in_snapshot,
639
654
_in_progress_tables } = snapshot;
640
655
641
656
self . in_snapshot . set ( was_in_snapshot) ;
657
+ self . universe . set ( universe) ;
642
658
643
659
self . projection_cache
644
660
. borrow_mut ( )
@@ -667,6 +683,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
667
683
float_snapshot,
668
684
region_constraints_snapshot,
669
685
region_obligations_snapshot : _,
686
+ universe : _,
670
687
was_in_snapshot,
671
688
_in_progress_tables } = snapshot;
672
689
@@ -811,7 +828,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
811
828
812
829
Some ( self . commit_if_ok ( |snapshot| {
813
830
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) ;
815
832
816
833
let cause_span = cause. span ;
817
834
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> {
828
845
{
829
846
self . commit_if_ok ( |snapshot| {
830
847
let ( ty:: OutlivesPredicate ( r_a, r_b) , skol_map) =
831
- self . skolemize_late_bound_regions ( predicate, snapshot ) ;
848
+ self . skolemize_late_bound_regions ( predicate) ;
832
849
let origin =
833
850
SubregionOrigin :: from_obligation_cause ( cause,
834
851
|| RelateRegionParamBound ( cause. span ) ) ;
@@ -841,7 +858,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
841
858
pub fn next_ty_var_id ( & self , diverging : bool , origin : TypeVariableOrigin ) -> TyVid {
842
859
self . type_variables
843
860
. borrow_mut ( )
844
- . new_var ( diverging, origin)
861
+ . new_var ( self . universe ( ) , diverging, origin)
845
862
}
846
863
847
864
pub fn next_ty_var ( & self , origin : TypeVariableOrigin ) -> Ty < ' tcx > {
@@ -872,12 +889,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
872
889
/// during diagnostics / error-reporting.
873
890
pub fn next_region_var ( & self , origin : RegionVariableOrigin )
874
891
-> 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) )
876
895
}
877
896
878
897
/// Number of region variables created so far.
879
898
pub fn num_region_vars ( & self ) -> usize {
880
- self . borrow_region_constraints ( ) . var_origins ( ) . len ( )
899
+ self . borrow_region_constraints ( ) . num_region_vars ( )
881
900
}
882
901
883
902
/// Just a convenient wrapper of `next_region_var` for using during NLL.
@@ -909,7 +928,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
909
928
-> Ty < ' tcx > {
910
929
let ty_var_id = self . type_variables
911
930
. borrow_mut ( )
912
- . new_var ( false ,
931
+ . new_var ( self . universe ( ) ,
932
+ false ,
913
933
TypeVariableOrigin :: TypeParameterDefinition ( span, def. name ) ) ;
914
934
915
935
self . tcx . mk_var ( ty_var_id)
@@ -1004,12 +1024,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1004
1024
region_context,
1005
1025
region_map,
1006
1026
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 ( )
1008
1028
. take ( )
1009
1029
. expect ( "regions already resolved" )
1010
- . into_origins_and_data ( ) ;
1030
+ . into_infos_and_data ( ) ;
1011
1031
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) ;
1013
1033
1014
1034
let old_value = self . lexical_region_resolutions . replace ( Some ( lexical_region_resolutions) ) ;
1015
1035
assert ! ( old_value. is_none( ) ) ;
@@ -1057,13 +1077,13 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1057
1077
/// hence that `resolve_regions_and_report_errors` can never be
1058
1078
/// called. This is used only during NLL processing to "hand off" ownership
1059
1079
/// 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 ( )
1062
1082
. take ( )
1063
1083
. expect ( "regions already resolved" )
1064
- . into_origins_and_data ( ) ;
1084
+ . into_infos_and_data ( ) ;
1065
1085
assert ! ( data. is_empty( ) ) ;
1066
- var_origins
1086
+ var_infos
1067
1087
}
1068
1088
1069
1089
pub fn ty_to_string ( & self , t : Ty < ' tcx > ) -> String {
@@ -1356,6 +1376,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
1356
1376
self . evaluation_cache . clear ( ) ;
1357
1377
self . projection_cache . borrow_mut ( ) . clear ( ) ;
1358
1378
}
1379
+
1380
+ fn universe ( & self ) -> ty:: UniverseIndex {
1381
+ self . universe . get ( )
1382
+ }
1359
1383
}
1360
1384
1361
1385
impl < ' a , ' gcx , ' tcx > TypeTrace < ' tcx > {
0 commit comments