@@ -44,7 +44,6 @@ impl<A> AutoTraitResult<A> {
44
44
pub struct AutoTraitInfo < ' cx > {
45
45
pub full_user_env : ty:: ParamEnv < ' cx > ,
46
46
pub region_data : RegionConstraintData < ' cx > ,
47
- pub names_map : FxHashSet < String > ,
48
47
pub vid_to_region : FxHashMap < ty:: RegionVid , ty:: Region < ' cx > > ,
49
48
}
50
49
@@ -77,15 +76,12 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
77
76
/// in the future.
78
77
pub fn find_auto_trait_generics < A > (
79
78
& self ,
80
- did : DefId ,
79
+ ty : Ty < ' tcx > ,
80
+ orig_env : ty:: ParamEnv < ' tcx > ,
81
81
trait_did : DefId ,
82
- generics : & ty:: Generics ,
83
82
auto_trait_callback : impl for < ' i > Fn ( & InferCtxt < ' _ , ' tcx , ' i > , AutoTraitInfo < ' i > ) -> A ,
84
83
) -> AutoTraitResult < A > {
85
84
let tcx = self . tcx ;
86
- let ty = self . tcx . type_of ( did) ;
87
-
88
- let orig_params = tcx. param_env ( did) ;
89
85
90
86
let trait_ref = ty:: TraitRef {
91
87
def_id : trait_did,
@@ -98,16 +94,16 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
98
94
let mut selcx = SelectionContext :: with_negative ( & infcx, true ) ;
99
95
let result = selcx. select ( & Obligation :: new (
100
96
ObligationCause :: dummy ( ) ,
101
- orig_params ,
97
+ orig_env ,
102
98
trait_pred. to_poly_trait_predicate ( ) ,
103
99
) ) ;
104
100
105
101
match result {
106
102
Ok ( Some ( Vtable :: VtableImpl ( _) ) ) => {
107
103
debug ! (
108
- "find_auto_trait_generics(did={:?}, trait_did={:?}, generics= {:?}): \
104
+ "find_auto_trait_generics({:?}): \
109
105
manual impl found, bailing out",
110
- did , trait_did , generics
106
+ trait_ref
111
107
) ;
112
108
true
113
109
}
@@ -158,11 +154,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
158
154
159
155
let ( new_env, user_env) = match self . evaluate_predicates (
160
156
& mut infcx,
161
- did,
162
157
trait_did,
163
158
ty,
164
- orig_params . clone ( ) ,
165
- orig_params ,
159
+ orig_env ,
160
+ orig_env ,
166
161
& mut fresh_preds,
167
162
false ,
168
163
) {
@@ -172,24 +167,23 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
172
167
173
168
let ( full_env, full_user_env) = self . evaluate_predicates (
174
169
& mut infcx,
175
- did,
176
170
trait_did,
177
171
ty,
178
- new_env. clone ( ) ,
172
+ new_env,
179
173
user_env,
180
174
& mut fresh_preds,
181
175
true ,
182
176
) . unwrap_or_else ( || {
183
177
panic ! (
184
178
"Failed to fully process: {:?} {:?} {:?}" ,
185
- ty, trait_did, orig_params
179
+ ty, trait_did, orig_env
186
180
)
187
181
} ) ;
188
182
189
183
debug ! (
190
- "find_auto_trait_generics(did={:?}, trait_did={:?}, generics= {:?}): fulfilling \
184
+ "find_auto_trait_generics({:?}): fulfilling \
191
185
with {:?}",
192
- did , trait_did , generics , full_env
186
+ trait_ref , full_env
193
187
) ;
194
188
infcx. clear_caches ( ) ;
195
189
@@ -211,23 +205,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
211
205
)
212
206
} ) ;
213
207
214
- let names_map: FxHashSet < String > = generics
215
- . params
216
- . iter ( )
217
- . filter_map ( |param| match param. kind {
218
- ty:: GenericParamDefKind :: Lifetime => Some ( param. name . to_string ( ) ) ,
219
- _ => None ,
220
- } )
221
- . collect ( ) ;
222
-
223
208
let body_id_map: FxHashMap < _ , _ > = infcx
224
209
. region_obligations
225
210
. borrow ( )
226
211
. iter ( )
227
212
. map ( |& ( id, _) | ( id, vec ! [ ] ) )
228
213
. collect ( ) ;
229
214
230
- infcx. process_registered_region_obligations ( & body_id_map, None , full_env. clone ( ) ) ;
215
+ infcx. process_registered_region_obligations ( & body_id_map, None , full_env) ;
231
216
232
217
let region_data = infcx
233
218
. borrow_region_constraints ( )
@@ -239,7 +224,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
239
224
let info = AutoTraitInfo {
240
225
full_user_env,
241
226
region_data,
242
- names_map,
243
227
vid_to_region,
244
228
} ;
245
229
@@ -286,10 +270,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
286
270
// the final synthesized generics: we don't want our generated docs page to contain something
287
271
// like 'T: Copy + Clone', as that's redundant. Therefore, we keep track of a separate
288
272
// 'user_env', which only holds the predicates that will actually be displayed to the user.
289
- pub fn evaluate_predicates < ' b , ' gcx , ' c > (
273
+ fn evaluate_predicates < ' b , ' gcx , ' c > (
290
274
& self ,
291
275
infcx : & InferCtxt < ' b , ' tcx , ' c > ,
292
- ty_did : DefId ,
293
276
trait_did : DefId ,
294
277
ty : Ty < ' c > ,
295
278
param_env : ty:: ParamEnv < ' c > ,
@@ -314,13 +297,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
314
297
let mut user_computed_preds: FxHashSet < _ > =
315
298
user_env. caller_bounds . iter ( ) . cloned ( ) . collect ( ) ;
316
299
317
- let mut new_env = param_env. clone ( ) ;
300
+ let mut new_env = param_env;
318
301
let dummy_cause = ObligationCause :: misc ( DUMMY_SP , hir:: DUMMY_HIR_ID ) ;
319
302
320
303
while let Some ( pred) = predicates. pop_front ( ) {
321
304
infcx. clear_caches ( ) ;
322
305
323
- if !already_visited. insert ( pred. clone ( ) ) {
306
+ if !already_visited. insert ( pred) {
324
307
continue ;
325
308
}
326
309
@@ -368,7 +351,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
368
351
already_visited. remove ( & pred) ;
369
352
self . add_user_pred (
370
353
& mut user_computed_preds,
371
- ty:: Predicate :: Trait ( pred. clone ( ) ) ,
354
+ ty:: Predicate :: Trait ( pred) ,
372
355
) ;
373
356
predicates. push_back ( pred) ;
374
357
} else {
@@ -387,7 +370,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
387
370
388
371
computed_preds. extend ( user_computed_preds. iter ( ) . cloned ( ) ) ;
389
372
let normalized_preds =
390
- elaborate_predicates ( tcx, computed_preds. clone ( ) . into_iter ( ) . collect ( ) ) ;
373
+ elaborate_predicates ( tcx, computed_preds. iter ( ) . cloned ( ) . collect ( ) ) ;
391
374
new_env = ty:: ParamEnv :: new (
392
375
tcx. mk_predicates ( normalized_preds) ,
393
376
param_env. reveal ,
@@ -401,9 +384,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
401
384
None
402
385
) ;
403
386
debug ! (
404
- "evaluate_nested_obligations(ty_did ={:?}, trait_did={:?}): succeeded with '{:?}' \
387
+ "evaluate_nested_obligations(ty ={:?}, trait_did={:?}): succeeded with '{:?}' \
405
388
'{:?}'",
406
- ty_did , trait_did, new_env, final_user_env
389
+ ty , trait_did, new_env, final_user_env
407
390
) ;
408
391
409
392
return Some ( ( new_env, final_user_env) ) ;
@@ -522,28 +505,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
522
505
}
523
506
}
524
507
525
- pub fn region_name ( & self , region : Region < ' _ > ) -> Option < String > {
526
- match region {
527
- & ty:: ReEarlyBound ( r) => Some ( r. name . to_string ( ) ) ,
528
- _ => None ,
529
- }
530
- }
531
-
532
- pub fn get_lifetime ( & self , region : Region < ' _ > ,
533
- names_map : & FxHashMap < String , String > ) -> String {
534
- self . region_name ( region)
535
- . map ( |name|
536
- names_map. get ( & name) . unwrap_or_else ( ||
537
- panic ! ( "Missing lifetime with name {:?} for {:?}" , name, region)
538
- )
539
- )
540
- . cloned ( )
541
- . unwrap_or_else ( || "'static" . to_owned ( ) )
542
- }
543
-
544
508
// This is very similar to handle_lifetimes. However, instead of matching ty::Region's
545
509
// to each other, we match ty::RegionVid's to ty::Region's
546
- pub fn map_vid_to_region < ' cx > (
510
+ fn map_vid_to_region < ' cx > (
547
511
& self ,
548
512
regions : & RegionConstraintData < ' cx > ,
549
513
) -> FxHashMap < ty:: RegionVid , ty:: Region < ' cx > > {
@@ -653,7 +617,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
653
617
}
654
618
}
655
619
656
- pub fn evaluate_nested_obligations <
620
+ fn evaluate_nested_obligations <
657
621
' b ,
658
622
' c ,
659
623
' d ,
@@ -672,10 +636,10 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
672
636
let dummy_cause = ObligationCause :: misc ( DUMMY_SP , hir:: DUMMY_HIR_ID ) ;
673
637
674
638
for ( obligation, mut predicate) in nested
675
- . map ( |o| ( o. clone ( ) , o. predicate . clone ( ) ) )
639
+ . map ( |o| ( o. clone ( ) , o. predicate ) )
676
640
{
677
641
let is_new_pred =
678
- fresh_preds. insert ( self . clean_pred ( select. infcx ( ) , predicate. clone ( ) ) ) ;
642
+ fresh_preds. insert ( self . clean_pred ( select. infcx ( ) , predicate) ) ;
679
643
680
644
// Resolve any inference variables that we can, to help selection succeed
681
645
predicate = select. infcx ( ) . resolve_type_vars_if_possible ( & predicate) ;
@@ -693,14 +657,14 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
693
657
// We check this by calling is_of_param on the relevant types
694
658
// from the various possible predicates
695
659
match & predicate {
696
- & ty:: Predicate :: Trait ( ref p) => {
660
+ & ty:: Predicate :: Trait ( p) => {
697
661
if self . is_param_no_infer ( p. skip_binder ( ) . trait_ref . substs )
698
662
&& !only_projections
699
663
&& is_new_pred {
700
664
701
665
self . add_user_pred ( computed_preds, predicate) ;
702
666
}
703
- predicates. push_back ( p. clone ( ) ) ;
667
+ predicates. push_back ( p) ;
704
668
}
705
669
& ty:: Predicate :: Projection ( p) => {
706
670
debug ! ( "evaluate_nested_obligations: examining projection predicate {:?}" ,
@@ -742,7 +706,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
742
706
if p. ty ( ) . skip_binder ( ) . has_infer_types ( ) {
743
707
debug ! ( "Projecting and unifying projection predicate {:?}" ,
744
708
predicate) ;
745
- match poly_project_and_unify_type ( select, & obligation. with ( p. clone ( ) ) ) {
709
+ match poly_project_and_unify_type ( select, & obligation. with ( p) ) {
746
710
Err ( e) => {
747
711
debug ! (
748
712
"evaluate_nested_obligations: Unable to unify predicate \
0 commit comments