@@ -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
@@ -99,23 +99,11 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
99
99
self . add_outlives ( r1_vid, r2_vid) ;
100
100
}
101
101
102
- GenericArgKind :: Type ( mut t1) => {
102
+ GenericArgKind :: Type ( t1) => {
103
103
// we don't actually use this for anything, but
104
104
// the `TypeOutlives` code needs an origin.
105
105
let origin = infer:: RelateParamBound ( DUMMY_SP , t1, None ) ;
106
106
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
-
119
107
TypeOutlives :: new (
120
108
& mut * self ,
121
109
tcx,
@@ -133,14 +121,32 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
133
121
}
134
122
}
135
123
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
+
136
143
fn verify_to_type_test (
137
144
& mut self ,
138
145
generic_kind : GenericKind < ' tcx > ,
139
146
region : ty:: Region < ' tcx > ,
140
147
verify_bound : VerifyBound < ' tcx > ,
141
148
) -> TypeTest < ' tcx > {
142
149
let lower_bound = self . to_region_vid ( region) ;
143
-
144
150
TypeTest { generic_kind, lower_bound, locations : self . locations , verify_bound }
145
151
}
146
152
@@ -188,6 +194,8 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
188
194
a : ty:: Region < ' tcx > ,
189
195
bound : VerifyBound < ' tcx > ,
190
196
) {
197
+ let kind = self . replace_placeholders_with_nll ( kind) ;
198
+ let bound = self . replace_placeholders_with_nll ( bound) ;
191
199
let type_test = self . verify_to_type_test ( kind, a, bound) ;
192
200
self . add_type_test ( type_test) ;
193
201
}
0 commit comments