@@ -6,7 +6,7 @@ use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
66use rustc_infer:: infer:: { self , InferCtxt , SubregionOrigin } ;
77use rustc_middle:: mir:: ConstraintCategory ;
88use rustc_middle:: ty:: subst:: GenericArgKind ;
9- use rustc_middle:: ty:: TypeVisitable ;
9+ use rustc_middle:: ty:: TypeFoldable ;
1010use rustc_middle:: ty:: { self , TyCtxt } ;
1111use rustc_span:: { Span , DUMMY_SP } ;
1212
@@ -99,23 +99,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
9999 self . add_outlives ( r1_vid, r2_vid) ;
100100 }
101101
102- GenericArgKind :: Type ( mut t1) => {
102+ GenericArgKind :: Type ( t1) => {
103103 // we don't actually use this for anything, but
104104 // the `TypeOutlives` code needs an origin.
105105 let origin = infer:: RelateParamBound ( DUMMY_SP , t1, None ) ;
106106
107- // Placeholder regions need to be converted now because it may
108- // create new region variables, which can't be done later when
109- // verifying these bounds.
110- if t1. has_placeholders ( ) {
111- t1 = tcx. fold_regions ( t1, |r, _| match * r {
112- ty:: RePlaceholder ( placeholder) => {
113- self . constraints . placeholder_region ( self . infcx , placeholder)
114- }
115- _ => r,
116- } ) ;
117- }
118-
119107 TypeOutlives :: new (
120108 & mut * self ,
121109 tcx,
@@ -133,14 +121,32 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
133121 }
134122 }
135123
124+ /// Placeholder regions need to be converted eagerly because it may
125+ /// create new region variables, which we must not do when verifying
126+ /// our region bounds.
127+ ///
128+ /// FIXME: This should get removed once higher ranked region obligations
129+ /// are dealt with during trait solving.
130+ fn replace_placeholders_with_nll < T : TypeFoldable < ' tcx > > ( & mut self , value : T ) -> T {
131+ if value. has_placeholders ( ) {
132+ self . tcx . fold_regions ( value, |r, _| match * r {
133+ ty:: RePlaceholder ( placeholder) => {
134+ self . constraints . placeholder_region ( self . infcx , placeholder)
135+ }
136+ _ => r,
137+ } )
138+ } else {
139+ value
140+ }
141+ }
142+
136143 fn verify_to_type_test (
137144 & mut self ,
138145 generic_kind : GenericKind < ' tcx > ,
139146 region : ty:: Region < ' tcx > ,
140147 verify_bound : VerifyBound < ' tcx > ,
141148 ) -> TypeTest < ' tcx > {
142149 let lower_bound = self . to_region_vid ( region) ;
143-
144150 TypeTest { generic_kind, lower_bound, locations : self . locations , verify_bound }
145151 }
146152
@@ -188,6 +194,8 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
188194 a : ty:: Region < ' tcx > ,
189195 bound : VerifyBound < ' tcx > ,
190196 ) {
197+ let kind = self . replace_placeholders_with_nll ( kind) ;
198+ let bound = self . replace_placeholders_with_nll ( bound) ;
191199 let type_test = self . verify_to_type_test ( kind, a, bound) ;
192200 self . add_type_test ( type_test) ;
193201 }
0 commit comments