@@ -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
@@ -109,23 +109,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
109109 self . add_outlives ( r1_vid, r2_vid) ;
110110 }
111111
112- GenericArgKind :: Type ( mut t1) => {
112+ GenericArgKind :: Type ( t1) => {
113113 // we don't actually use this for anything, but
114114 // the `TypeOutlives` code needs an origin.
115115 let origin = infer:: RelateParamBound ( DUMMY_SP , t1, None ) ;
116116
117- // Placeholder regions need to be converted now because it may
118- // create new region variables, which can't be done later when
119- // verifying these bounds.
120- if t1. has_placeholders ( ) {
121- t1 = tcx. fold_regions ( t1, |r, _| match * r {
122- ty:: RePlaceholder ( placeholder) => {
123- self . constraints . placeholder_region ( self . infcx , placeholder)
124- }
125- _ => r,
126- } ) ;
127- }
128-
129117 TypeOutlives :: new (
130118 & mut * self ,
131119 tcx,
@@ -143,14 +131,32 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
143131 }
144132 }
145133
134+ /// Placeholder regions need to be converted eagerly because it may
135+ /// create new region variables, which we must not do when verifying
136+ /// our region bounds.
137+ ///
138+ /// FIXME: This should get removed once higher ranked region obligations
139+ /// are dealt with during trait solving.
140+ fn replace_placeholders_with_nll < T : TypeFoldable < ' tcx > > ( & mut self , value : T ) -> T {
141+ if value. has_placeholders ( ) {
142+ self . tcx . fold_regions ( value, |r, _| match * r {
143+ ty:: RePlaceholder ( placeholder) => {
144+ self . constraints . placeholder_region ( self . infcx , placeholder)
145+ }
146+ _ => r,
147+ } )
148+ } else {
149+ value
150+ }
151+ }
152+
146153 fn verify_to_type_test (
147154 & mut self ,
148155 generic_kind : GenericKind < ' tcx > ,
149156 region : ty:: Region < ' tcx > ,
150157 verify_bound : VerifyBound < ' tcx > ,
151158 ) -> TypeTest < ' tcx > {
152159 let lower_bound = self . to_region_vid ( region) ;
153-
154160 TypeTest { generic_kind, lower_bound, locations : self . locations , verify_bound }
155161 }
156162
@@ -198,6 +204,8 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
198204 a : ty:: Region < ' tcx > ,
199205 bound : VerifyBound < ' tcx > ,
200206 ) {
207+ let kind = self . replace_placeholders_with_nll ( kind) ;
208+ let bound = self . replace_placeholders_with_nll ( bound) ;
201209 let type_test = self . verify_to_type_test ( kind, a, bound) ;
202210 self . add_type_test ( type_test) ;
203211 }
0 commit comments