@@ -6,7 +6,7 @@ use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound};
6
6
use rustc_infer:: infer:: { self , InferCtxt , SubregionOrigin } ;
7
7
use rustc_middle:: mir:: ConstraintCategory ;
8
8
use rustc_middle:: ty:: subst:: GenericArgKind ;
9
- use rustc_middle:: ty:: TypeVisitable ;
9
+ use rustc_middle:: ty:: TypeFoldable ;
10
10
use rustc_middle:: ty:: { self , TyCtxt } ;
11
11
use rustc_span:: { Span , DUMMY_SP } ;
12
12
@@ -109,23 +109,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
109
109
self . add_outlives ( r1_vid, r2_vid) ;
110
110
}
111
111
112
- GenericArgKind :: Type ( mut t1) => {
112
+ GenericArgKind :: Type ( t1) => {
113
113
// we don't actually use this for anything, but
114
114
// the `TypeOutlives` code needs an origin.
115
115
let origin = infer:: RelateParamBound ( DUMMY_SP , t1, None ) ;
116
116
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
-
129
117
TypeOutlives :: new (
130
118
& mut * self ,
131
119
tcx,
@@ -143,14 +131,32 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
143
131
}
144
132
}
145
133
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
+
146
153
fn verify_to_type_test (
147
154
& mut self ,
148
155
generic_kind : GenericKind < ' tcx > ,
149
156
region : ty:: Region < ' tcx > ,
150
157
verify_bound : VerifyBound < ' tcx > ,
151
158
) -> TypeTest < ' tcx > {
152
159
let lower_bound = self . to_region_vid ( region) ;
153
-
154
160
TypeTest { generic_kind, lower_bound, locations : self . locations , verify_bound }
155
161
}
156
162
@@ -198,6 +204,8 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
198
204
a : ty:: Region < ' tcx > ,
199
205
bound : VerifyBound < ' tcx > ,
200
206
) {
207
+ let kind = self . replace_placeholders_with_nll ( kind) ;
208
+ let bound = self . replace_placeholders_with_nll ( bound) ;
201
209
let type_test = self . verify_to_type_test ( kind, a, bound) ;
202
210
self . add_type_test ( type_test) ;
203
211
}
0 commit comments