@@ -21,42 +21,38 @@ struct RegionDeps<'tcx> {
21
21
}
22
22
23
23
crate struct AutoTraitFinder < ' a , ' tcx > {
24
- crate cx : & ' a core:: DocContext < ' tcx > ,
25
- crate f : auto_trait:: AutoTraitFinder < ' tcx > ,
24
+ crate cx : & ' a mut core:: DocContext < ' tcx > ,
26
25
}
27
26
28
27
impl < ' a , ' tcx > AutoTraitFinder < ' a , ' tcx > {
29
- crate fn new ( cx : & ' a core:: DocContext < ' tcx > ) -> Self {
30
- let f = auto_trait:: AutoTraitFinder :: new ( cx. tcx ) ;
31
-
32
- AutoTraitFinder { cx, f }
28
+ crate fn new ( cx : & ' a mut core:: DocContext < ' tcx > ) -> Self {
29
+ AutoTraitFinder { cx }
33
30
}
34
31
35
32
// FIXME(eddyb) figure out a better way to pass information about
36
33
// parametrization of `ty` than `param_env_def_id`.
37
- crate fn get_auto_trait_impls ( & self , ty : Ty < ' tcx > , param_env_def_id : DefId ) -> Vec < Item > {
38
- let param_env = self . cx . tcx . param_env ( param_env_def_id) ;
34
+ crate fn get_auto_trait_impls ( & mut self , ty : Ty < ' tcx > , param_env_def_id : DefId ) -> Vec < Item > {
35
+ let tcx = self . cx . tcx ;
36
+ let param_env = tcx. param_env ( param_env_def_id) ;
37
+ let f = auto_trait:: AutoTraitFinder :: new ( self . cx . tcx ) ;
39
38
40
39
debug ! ( "get_auto_trait_impls({:?})" , ty) ;
41
- let auto_traits = self . cx . auto_traits . iter ( ) . cloned ( ) ;
40
+ let auto_traits: Vec < _ > = self . cx . auto_traits . iter ( ) . cloned ( ) . collect ( ) ;
42
41
auto_traits
42
+ . into_iter ( )
43
43
. filter_map ( |trait_def_id| {
44
- let trait_ref = ty:: TraitRef {
45
- def_id : trait_def_id,
46
- substs : self . cx . tcx . mk_substs_trait ( ty, & [ ] ) ,
47
- } ;
44
+ let trait_ref =
45
+ ty:: TraitRef { def_id : trait_def_id, substs : tcx. mk_substs_trait ( ty, & [ ] ) } ;
48
46
if !self . cx . generated_synthetics . borrow_mut ( ) . insert ( ( ty, trait_def_id) ) {
49
47
debug ! ( "get_auto_trait_impl_for({:?}): already generated, aborting" , trait_ref) ;
50
48
return None ;
51
49
}
52
50
53
51
let result =
54
- self . f . find_auto_trait_generics ( ty, param_env, trait_def_id, |infcx, info| {
52
+ f. find_auto_trait_generics ( ty, param_env, trait_def_id, |infcx, info| {
55
53
let region_data = info. region_data ;
56
54
57
- let names_map = self
58
- . cx
59
- . tcx
55
+ let names_map = tcx
60
56
. generics_of ( param_env_def_id)
61
57
. params
62
58
. iter ( )
@@ -66,7 +62,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
66
62
} )
67
63
. map ( |name| ( name, Lifetime ( name) ) )
68
64
. collect ( ) ;
69
- let lifetime_predicates = self . handle_lifetimes ( & region_data, & names_map) ;
65
+ let lifetime_predicates = Self :: handle_lifetimes ( & region_data, & names_map) ;
70
66
let new_generics = self . param_env_to_generics (
71
67
infcx. tcx ,
72
68
param_env_def_id,
@@ -105,12 +101,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
105
101
// Instead, we generate `impl !Send for Foo<T>`, which better
106
102
// expresses the fact that `Foo<T>` never implements `Send`,
107
103
// regardless of the choice of `T`.
108
- let params = (
109
- self . cx . tcx . generics_of ( param_env_def_id) ,
110
- ty:: GenericPredicates :: default ( ) ,
111
- )
112
- . clean ( self . cx )
113
- . params ;
104
+ let params =
105
+ ( tcx. generics_of ( param_env_def_id) , ty:: GenericPredicates :: default ( ) )
106
+ . clean ( self . cx )
107
+ . params ;
114
108
115
109
Generics { params, where_predicates : Vec :: new ( ) }
116
110
}
@@ -139,12 +133,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
139
133
. collect ( )
140
134
}
141
135
142
- fn get_lifetime (
143
- & self ,
144
- region : Region < ' _ > ,
145
- names_map : & FxHashMap < Symbol , Lifetime > ,
146
- ) -> Lifetime {
147
- self . region_name ( region)
136
+ fn get_lifetime ( region : Region < ' _ > , names_map : & FxHashMap < Symbol , Lifetime > ) -> Lifetime {
137
+ region_name ( region)
148
138
. map ( |name| {
149
139
names_map. get ( & name) . unwrap_or_else ( || {
150
140
panic ! ( "Missing lifetime with name {:?} for {:?}" , name. as_str( ) , region)
@@ -154,13 +144,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
154
144
. clone ( )
155
145
}
156
146
157
- fn region_name ( & self , region : Region < ' _ > ) -> Option < Symbol > {
158
- match region {
159
- & ty:: ReEarlyBound ( r) => Some ( r. name ) ,
160
- _ => None ,
161
- }
162
- }
163
-
164
147
// This method calculates two things: Lifetime constraints of the form 'a: 'b,
165
148
// and region constraints of the form ReVar: 'a
166
149
//
@@ -172,7 +155,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
172
155
// to perform the calculations we need on our own, rather than trying to make
173
156
// existing inference/solver code do what we want.
174
157
fn handle_lifetimes < ' cx > (
175
- & self ,
176
158
regions : & RegionConstraintData < ' cx > ,
177
159
names_map : & FxHashMap < Symbol , Lifetime > ,
178
160
) -> Vec < WherePredicate > {
@@ -210,9 +192,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
210
192
& Constraint :: RegSubReg ( r1, r2) => {
211
193
// The constraint is already in the form that we want, so we're done with it
212
194
// Desired order is 'larger, smaller', so flip then
213
- if self . region_name ( r1) != self . region_name ( r2) {
195
+ if region_name ( r1) != region_name ( r2) {
214
196
finished
215
- . entry ( self . region_name ( r2) . expect ( "no region_name found" ) )
197
+ . entry ( region_name ( r2) . expect ( "no region_name found" ) )
216
198
. or_default ( )
217
199
. push ( r1) ;
218
200
}
@@ -245,9 +227,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
245
227
for larger in deps. larger . iter ( ) {
246
228
match ( smaller, larger) {
247
229
( & RegionTarget :: Region ( r1) , & RegionTarget :: Region ( r2) ) => {
248
- if self . region_name ( r1) != self . region_name ( r2) {
230
+ if region_name ( r1) != region_name ( r2) {
249
231
finished
250
- . entry ( self . region_name ( r2) . expect ( "no region name found" ) )
232
+ . entry ( region_name ( r2) . expect ( "no region name found" ) )
251
233
. or_default ( )
252
234
. push ( r1) // Larger, smaller
253
235
}
@@ -292,7 +274,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
292
274
. get ( name)
293
275
. unwrap_or ( & empty)
294
276
. iter ( )
295
- . map ( |region| GenericBound :: Outlives ( self . get_lifetime ( region, names_map) ) )
277
+ . map ( |region| GenericBound :: Outlives ( Self :: get_lifetime ( region, names_map) ) )
296
278
. collect ( ) ;
297
279
298
280
if bounds. is_empty ( ) {
@@ -437,7 +419,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
437
419
// K', we use the dedicated syntax 'T: Fn() -> K'
438
420
// * We explicitly add a '?Sized' bound if we didn't find any 'Sized' predicates for a type
439
421
fn param_env_to_generics (
440
- & self ,
422
+ & mut self ,
441
423
tcx : TyCtxt < ' tcx > ,
442
424
param_env_def_id : DefId ,
443
425
param_env : ty:: ParamEnv < ' tcx > ,
@@ -468,10 +450,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
468
450
_ => false ,
469
451
}
470
452
} )
471
- . map ( |p| {
472
- let replaced = p. fold_with ( & mut replacer) ;
473
- ( replaced, replaced. clean ( self . cx ) )
474
- } ) ;
453
+ . map ( |p| p. fold_with ( & mut replacer) ) ;
475
454
476
455
let mut generic_params =
477
456
( tcx. generics_of ( param_env_def_id) , tcx. explicit_predicates_of ( param_env_def_id) )
@@ -490,7 +469,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
490
469
491
470
let mut ty_to_fn: FxHashMap < Type , ( Option < PolyTrait > , Option < Type > ) > = Default :: default ( ) ;
492
471
493
- for ( orig_p, p) in clean_where_predicates {
472
+ for p in clean_where_predicates {
473
+ let ( orig_p, p) = ( p, p. clean ( self . cx ) ) ;
494
474
if p. is_none ( ) {
495
475
continue ;
496
476
}
@@ -749,6 +729,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
749
729
}
750
730
}
751
731
732
+ fn region_name ( region : Region < ' _ > ) -> Option < Symbol > {
733
+ match region {
734
+ & ty:: ReEarlyBound ( r) => Some ( r. name ) ,
735
+ _ => None ,
736
+ }
737
+ }
738
+
752
739
// Replaces all ReVars in a type with ty::Region's, using the provided map
753
740
struct RegionReplacer < ' a , ' tcx > {
754
741
vid_to_region : & ' a FxHashMap < ty:: RegionVid , ty:: Region < ' tcx > > ,
0 commit comments