1
- use std:: cell:: RefCell ;
2
-
3
1
use crate :: hir:: def_id:: DefId ;
4
2
use crate :: infer:: outlives:: env:: RegionBoundPairs ;
5
3
use crate :: infer:: { GenericKind , VerifyBound } ;
6
4
use crate :: traits;
7
5
use crate :: ty:: subst:: { InternalSubsts , Subst } ;
8
6
use crate :: ty:: { self , Ty , TyCtxt } ;
9
- use crate :: util:: captures:: Captures ;
7
+ use crate :: util:: captures:: { Captures , Captures2 } ;
10
8
11
9
/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
12
10
/// obligation into a series of `'a: 'b` constraints and "verifys", as
@@ -19,7 +17,7 @@ pub struct VerifyBoundCx<'cx, 'tcx> {
19
17
region_bound_pairs : & ' cx RegionBoundPairs < ' tcx > ,
20
18
implicit_region_bound : Option < ty:: Region < ' tcx > > ,
21
19
param_env : ty:: ParamEnv < ' tcx > ,
22
- elaborator : RefCell < traits:: Elaborator < ' tcx > > ,
20
+ elaborator : traits:: Elaborator < ' tcx > ,
23
21
}
24
22
25
23
impl < ' cx , ' tcx > VerifyBoundCx < ' cx , ' tcx > {
@@ -34,20 +32,20 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
34
32
region_bound_pairs,
35
33
implicit_region_bound,
36
34
param_env,
37
- elaborator : RefCell :: new ( traits:: Elaborator :: new ( tcx) ) ,
35
+ elaborator : traits:: Elaborator :: new ( tcx) ,
38
36
}
39
37
}
40
38
41
39
/// Returns a "verify bound" that encodes what we know about
42
40
/// `generic` and the regions it outlives.
43
- pub fn generic_bound ( & self , generic : GenericKind < ' tcx > ) -> VerifyBound < ' tcx > {
41
+ pub fn generic_bound ( & mut self , generic : GenericKind < ' tcx > ) -> VerifyBound < ' tcx > {
44
42
match generic {
45
43
GenericKind :: Param ( param_ty) => self . param_bound ( param_ty) ,
46
44
GenericKind :: Projection ( projection_ty) => self . projection_bound ( projection_ty) ,
47
45
}
48
46
}
49
47
50
- fn type_bound ( & self , ty : Ty < ' tcx > ) -> VerifyBound < ' tcx > {
48
+ fn type_bound ( & mut self , ty : Ty < ' tcx > ) -> VerifyBound < ' tcx > {
51
49
match ty. kind {
52
50
ty:: Param ( p) => self . param_bound ( p) ,
53
51
ty:: Projection ( data) => self . projection_bound ( data) ,
@@ -86,7 +84,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
86
84
pub fn projection_approx_declared_bounds_from_env (
87
85
& self ,
88
86
projection_ty : ty:: ProjectionTy < ' tcx > ,
89
- ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + ' cx + Captures < ' tcx >
87
+ ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + Captures2 < ' cx , ' tcx >
90
88
{
91
89
let tcx = self . tcx ;
92
90
@@ -106,16 +104,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
106
104
/// `projection_ty` is known to outlive. Currently requires an
107
105
/// exact match.
108
106
pub fn projection_declared_bounds_from_trait < ' a > (
109
- & ' a self ,
107
+ & ' a mut self ,
110
108
projection_ty : ty:: ProjectionTy < ' tcx > ,
111
- ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > + ' a
112
- where
113
- ' a : ' cx ,
114
- {
109
+ ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' a + Captures2 < ' cx , ' tcx > {
115
110
self . declared_projection_bounds_from_trait ( projection_ty)
116
111
}
117
112
118
- pub fn projection_bound ( & self , projection_ty : ty:: ProjectionTy < ' tcx > ) -> VerifyBound < ' tcx > {
113
+ pub fn projection_bound ( & mut self , projection_ty : ty:: ProjectionTy < ' tcx > ) -> VerifyBound < ' tcx > {
119
114
debug ! ( "projection_bound(projection_ty={:?})" , projection_ty) ;
120
115
121
116
let projection_ty_as_ty =
@@ -151,7 +146,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
151
146
} )
152
147
}
153
148
154
- fn recursive_type_bound ( & self , ty : Ty < ' tcx > ) -> VerifyBound < ' tcx > {
149
+ fn recursive_type_bound ( & mut self , ty : Ty < ' tcx > ) -> VerifyBound < ' tcx > {
155
150
let mut bounds = ty
156
151
. walk_shallow ( )
157
152
. map ( |subty| self . type_bound ( subty) )
@@ -177,16 +172,16 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
177
172
fn declared_generic_bounds_from_env (
178
173
& self ,
179
174
generic : ty:: ParamTy ,
180
- ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + ' cx + Captures < ' tcx >
175
+ ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + Captures2 < ' cx , ' tcx >
181
176
{
182
177
let generic_ty = generic. to_ty ( self . tcx ) ;
183
178
self . declared_generic_bounds_from_env_with_compare_fn ( move |ty| ty == generic_ty)
184
179
}
185
180
186
181
fn declared_generic_bounds_from_env_with_compare_fn (
187
182
& self ,
188
- compare_ty : impl Fn ( Ty < ' tcx > ) -> bool + Clone + ' tcx + ' cx ,
189
- ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + ' cx + Captures < ' tcx >
183
+ compare_ty : impl Fn ( Ty < ' tcx > ) -> bool + Clone + ' tcx + Captures < ' cx > ,
184
+ ) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > + Captures2 < ' cx , ' tcx >
190
185
{
191
186
let tcx = self . tcx ;
192
187
@@ -197,7 +192,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
197
192
// like `T` and `T::Item`. It may not work as well for things
198
193
// like `<T as Foo<'a>>::Item`.
199
194
let c_b = self . param_env . caller_bounds ;
200
- let param_bounds = self . collect_outlives_from_predicate_list ( compare_ty. clone ( ) , c_b) ;
195
+ let param_bounds = Self :: collect_outlives_from_predicate_list ( compare_ty. clone ( ) , c_b) ;
201
196
202
197
// Next, collect regions we scraped from the well-formedness
203
198
// constraints in the fn signature. To do that, we walk the list
@@ -240,12 +235,9 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
240
235
/// limitations around higher-ranked bounds described in
241
236
/// `region_bounds_declared_on_associated_item`.
242
237
fn declared_projection_bounds_from_trait < ' a > (
243
- & ' a self ,
238
+ & ' a mut self ,
244
239
projection_ty : ty:: ProjectionTy < ' tcx > ,
245
- ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > + ' a
246
- where
247
- ' a : ' cx ,
248
- {
240
+ ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' a + Captures2 < ' cx , ' tcx > {
249
241
debug ! ( "projection_bounds(projection_ty={:?})" , projection_ty) ;
250
242
let tcx = self . tcx ;
251
243
self . region_bounds_declared_on_associated_item ( projection_ty. item_def_id )
@@ -283,23 +275,20 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
283
275
/// This is for simplicity, and because we are not really smart
284
276
/// enough to cope with such bounds anywhere.
285
277
fn region_bounds_declared_on_associated_item < ' a > (
286
- & ' a self ,
278
+ & ' a mut self ,
287
279
assoc_item_def_id : DefId ,
288
- ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' cx + Captures < ' tcx > + ' a
289
- where
290
- ' a : ' cx ,
291
- {
280
+ ) -> impl Iterator < Item = ty:: Region < ' tcx > > + ' a + Captures2 < ' cx , ' tcx > {
292
281
let tcx = self . tcx ;
293
282
let assoc_item = tcx. associated_item ( assoc_item_def_id) ;
294
283
let trait_def_id = assoc_item. container . assert_trait ( ) ;
295
284
let trait_predicates = tcx. predicates_of ( trait_def_id) . predicates . iter ( ) . map ( |( p, _) | * p) ;
296
- let mut elaborator = self . elaborator . borrow_mut ( ) ;
285
+ let elaborator = & mut self . elaborator ;
297
286
elaborator. clear ( ) ;
298
287
elaborator. extend ( trait_predicates) ;
299
288
let identity_substs = InternalSubsts :: identity_for_item ( tcx, assoc_item_def_id) ;
300
289
let identity_proj = tcx. mk_projection ( assoc_item_def_id, identity_substs) ;
301
290
302
- self . collect_outlives_from_predicate_list (
291
+ Self :: collect_outlives_from_predicate_list (
303
292
move |ty| ty == identity_proj,
304
293
std:: iter:: from_fn ( move || elaborator. next ( ) ) ,
305
294
)
@@ -313,7 +302,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
313
302
/// that does not involve inference variables and where you
314
303
/// otherwise want a precise match.
315
304
fn collect_outlives_from_predicate_list (
316
- & self ,
317
305
compare_ty : impl Fn ( Ty < ' tcx > ) -> bool + ' tcx ,
318
306
predicates : impl IntoIterator < Item = impl AsRef < ty:: Predicate < ' tcx > > > ,
319
307
) -> impl Iterator < Item = ty:: OutlivesPredicate < Ty < ' tcx > , ty:: Region < ' tcx > > > {
0 commit comments