@@ -54,9 +54,9 @@ use crate::inherent::*;
5454use crate :: relate:: { Relate , RelateResult , TypeRelation , VarianceDiagInfo } ;
5555use crate :: visit:: TypeVisitableExt ;
5656use crate :: {
57- AliasTy , Binder , BoundRegion , BoundVar , BoundVariableKind , ClauseKind , DebruijnIndex ,
58- InferCtxtLike , Interner , IsRigid , OutlivesClause , Region , RegionKind , TyKind , TypeFoldable ,
59- TypeFolder , TypingMode , UniverseIndex , Variance , elaborate, max_universe,
57+ AliasTy , Binder , BoundRegion , BoundRegionKind , BoundVar , BoundVariableKind , ClauseKind ,
58+ DebruijnIndex , InferCtxtLike , Interner , IsRigid , OutlivesClause , Region , RegionKind , TyKind ,
59+ TypeFoldable , TypeFolder , TypingMode , UniverseIndex , Variance , elaborate, max_universe,
6060 set_aliases_to_non_rigid,
6161} ;
6262
@@ -964,16 +964,16 @@ fn rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handl
964964 let higher_ranked_candidate_for_outlived_region = |region| {
965965 let bound_outlives = bound_outlives. map_bound ( |( alias, _) | ( alias, region) ) ;
966966
967- let mut replacer = PlaceholderReplacer {
968- cx : infcx. cx ( ) ,
969- existing_var_count : bound_outlives. bound_vars ( ) . len ( ) ,
970- bound_vars : IndexMap :: default ( ) ,
967+ let mut replacer = MakeHigherRankederer {
968+ cx : infcx,
969+ preexisting_var_count : bound_outlives. bound_vars ( ) . len ( ) ,
970+ regions : IndexMap :: default ( ) ,
971971 universe : u,
972972 current_index : DebruijnIndex :: ZERO ,
973973 } ;
974974 let escaping_outlives = bound_outlives. skip_binder ( ) . fold_with ( & mut replacer) ;
975975 let bound_vars = bound_outlives. bound_vars ( ) . iter ( ) . chain (
976- core:: mem:: take ( & mut replacer. bound_vars )
976+ core:: mem:: take ( & mut replacer. regions )
977977 . into_iter ( )
978978 . map ( |( _, bound_region) | BoundVariableKind :: Region ( bound_region. kind ) ) ,
979979 ) ;
@@ -982,7 +982,7 @@ fn rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handl
982982 I :: BoundVarKinds :: from_vars ( infcx. cx ( ) , bound_vars) ,
983983 ) ;
984984
985- // `PlaceholderReplacer ` only folds regions. A non-lifetime binder can leave
985+ // `MakeHigherRankederer ` only folds regions. A non-lifetime binder can leave
986986 // a placeholder type in `u`, so this type-outlives constraint cannot be
987987 // handled by the region-outlives-only eager placeholder machinery.
988988 if max_universe ( infcx, bound_outlives) == u {
@@ -1078,30 +1078,52 @@ pub fn regions_outlived_by_placeholder<I: Interner>(
10781078 } )
10791079}
10801080
1081- pub struct PlaceholderReplacer < I : Interner > {
1082- cx : I ,
1083- existing_var_count : usize ,
1084- bound_vars : IndexMap < BoundVar , BoundRegion < I > > ,
1081+ pub struct MakeHigherRankederer < ' a , I : Interner , Infcx : InferCtxtLike < Interner = I > > {
1082+ cx : & ' a Infcx ,
1083+ preexisting_var_count : usize ,
1084+ regions : IndexMap < Region < I > , BoundRegion < I > > ,
10851085 universe : UniverseIndex ,
10861086 current_index : DebruijnIndex ,
10871087}
10881088
1089- impl < I : Interner > TypeFolder < I > for PlaceholderReplacer < I > {
1089+ impl < ' a , I : Interner , Infcx : InferCtxtLike < Interner = I > > MakeHigherRankederer < ' a , I , Infcx > {
1090+ fn existing_var_count ( & self ) -> usize {
1091+ self . preexisting_var_count + self . regions . len ( )
1092+ }
1093+ }
1094+
1095+ impl < ' a , I : Interner , Infcx : InferCtxtLike < Interner = I > > TypeFolder < I >
1096+ for MakeHigherRankederer < ' a , I , Infcx >
1097+ {
10901098 fn cx ( & self ) -> I {
1091- self . cx
1099+ self . cx . cx ( )
10921100 }
10931101
10941102 fn fold_region ( & mut self , r : Region < I > ) -> Region < I > {
1103+ let cx = self . cx ( ) ;
1104+
10951105 match r. kind ( ) {
10961106 RegionKind :: RePlaceholder ( p) if p. universe == self . universe => {
1097- let bound_vars_len = self . bound_vars . len ( ) ;
1098- let mapped_var = self . bound_vars . entry ( p . bound . var ) . or_insert ( BoundRegion {
1099- var : BoundVar :: from_usize ( self . existing_var_count + bound_vars_len ) ,
1107+ let existing_var_count = self . existing_var_count ( ) ;
1108+ let mapped_var = self . regions . entry ( r ) . or_insert ( BoundRegion {
1109+ var : BoundVar :: from_usize ( existing_var_count) ,
11001110 kind : p. bound . kind ,
11011111 } ) ;
1102- Region :: new_bound ( self . cx , self . current_index , * mapped_var)
1112+ Region :: new_bound ( cx, self . current_index , * mapped_var)
1113+ }
1114+ RegionKind :: ReVar ( inf) => {
1115+ let u = self . cx . universe_of_region ( inf) . unwrap ( ) ;
1116+ if u == self . universe {
1117+ let existing_var_count = self . existing_var_count ( ) ;
1118+ let mapped_var = self . regions . entry ( r) . or_insert ( BoundRegion {
1119+ var : BoundVar :: from_usize ( existing_var_count) ,
1120+ kind : BoundRegionKind :: Anon ,
1121+ } ) ;
1122+ Region :: new_bound ( cx, self . current_index , * mapped_var)
1123+ } else {
1124+ r
1125+ }
11031126 }
1104- // FIXME(-Zassumptions-on-binders): We should be handling region variables here somehow
11051127 _ => r,
11061128 }
11071129 }
0 commit comments