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