@@ -132,18 +132,18 @@ impl<'cx, 'gcx, 'tcx> Elaborator<'cx, 'gcx, 'tcx> {
132
132
// Get predicates declared on the trait.
133
133
let predicates = tcx. super_predicates_of ( data. def_id ( ) ) ;
134
134
135
- let mut predicates: Vec < _ > = predicates. predicates
135
+ let predicates = predicates. predicates
136
136
. iter ( )
137
- . map ( |( pred, _) | pred. subst_supertrait ( tcx, & data. to_poly_trait_ref ( ) ) )
138
- . collect ( ) ;
137
+ . map ( |( pred, _) | pred. subst_supertrait ( tcx, & data. to_poly_trait_ref ( ) ) ) ;
139
138
debug ! ( "super_predicates: data={:?} predicates={:?}" ,
140
- data, predicates) ;
139
+ data, predicates. clone ( ) ) ;
141
140
142
141
// Only keep those bounds that we haven't already seen.
143
142
// This is necessary to prevent infinite recursion in some
144
143
// cases. One common case is when people define
145
144
// `trait Sized: Sized { }` rather than `trait Sized { }`.
146
- predicates. retain ( |pred| self . visited . insert ( pred) ) ;
145
+ let visited = & mut self . visited ;
146
+ let predicates = predicates. filter ( |pred| visited. insert ( pred) ) ;
147
147
148
148
self . stack . extend ( predicates) ;
149
149
}
@@ -298,13 +298,21 @@ impl<'tcx> TraitAliasExpansionInfo<'tcx> {
298
298
}
299
299
}
300
300
301
- fn clone_and_push ( & self , trait_ref : ty:: PolyTraitRef < ' tcx > , span : Span ) -> Self {
302
- let mut path = self . path . clone ( ) ;
303
- path. push ( ( trait_ref, span) ) ;
304
-
305
- Self {
306
- path
301
+ /// Adds diagnostic labels to `diag` for the expansion path of a trait through all intermediate
302
+ /// trait aliases.
303
+ pub fn label_with_exp_info ( & self ,
304
+ diag : & mut DiagnosticBuilder < ' _ > ,
305
+ top_label : & str ,
306
+ use_desc : & str
307
+ ) {
308
+ diag. span_label ( self . top ( ) . 1 , top_label) ;
309
+ if self . path . len ( ) > 1 {
310
+ for ( _, sp) in self . path . iter ( ) . rev ( ) . skip ( 1 ) . take ( self . path . len ( ) - 2 ) {
311
+ diag. span_label ( * sp, format ! ( "referenced here ({})" , use_desc) ) ;
312
+ }
307
313
}
314
+ diag. span_label ( self . bottom ( ) . 1 ,
315
+ format ! ( "trait alias used in trait object type ({})" , use_desc) ) ;
308
316
}
309
317
310
318
pub fn trait_ref ( & self ) -> & ty:: PolyTraitRef < ' tcx > {
@@ -318,33 +326,14 @@ impl<'tcx> TraitAliasExpansionInfo<'tcx> {
318
326
pub fn bottom ( & self ) -> & ( ty:: PolyTraitRef < ' tcx > , Span ) {
319
327
self . path . first ( ) . unwrap ( )
320
328
}
321
- }
322
329
323
- /// Emits diagnostic information relating to the expansion of a trait via trait aliases
324
- /// (see [`TraitAliasExpansionInfo`]).
325
- pub trait TraitAliasExpansionInfoDignosticBuilder {
326
- fn label_with_exp_info < ' tcx > ( & mut self ,
327
- info : & TraitAliasExpansionInfo < ' tcx > ,
328
- top_label : & str ,
329
- use_desc : & str
330
- ) -> & mut Self ;
331
- }
330
+ fn clone_and_push ( & self , trait_ref : ty:: PolyTraitRef < ' tcx > , span : Span ) -> Self {
331
+ let mut path = self . path . clone ( ) ;
332
+ path. push ( ( trait_ref, span) ) ;
332
333
333
- impl < ' a > TraitAliasExpansionInfoDignosticBuilder for DiagnosticBuilder < ' a > {
334
- fn label_with_exp_info < ' tcx > ( & mut self ,
335
- info : & TraitAliasExpansionInfo < ' tcx > ,
336
- top_label : & str ,
337
- use_desc : & str
338
- ) -> & mut Self {
339
- self . span_label ( info. top ( ) . 1 , top_label) ;
340
- if info. path . len ( ) > 1 {
341
- for ( _, sp) in info. path . iter ( ) . rev ( ) . skip ( 1 ) . take ( info. path . len ( ) - 2 ) {
342
- self . span_label ( * sp, format ! ( "referenced here ({})" , use_desc) ) ;
343
- }
334
+ Self {
335
+ path
344
336
}
345
- self . span_label ( info. bottom ( ) . 1 ,
346
- format ! ( "trait alias used in trait object type ({})" , use_desc) ) ;
347
- self
348
337
}
349
338
}
350
339
@@ -388,16 +377,15 @@ impl<'cx, 'gcx, 'tcx> TraitAliasExpander<'cx, 'gcx, 'tcx> {
388
377
// Get components of trait alias.
389
378
let predicates = tcx. super_predicates_of ( trait_ref. def_id ( ) ) ;
390
379
391
- let items: Vec < _ > = predicates. predicates
380
+ let items = predicates. predicates
392
381
. iter ( )
393
382
. rev ( )
394
383
. filter_map ( |( pred, span) | {
395
384
pred. subst_supertrait ( tcx, & trait_ref)
396
385
. to_opt_poly_trait_ref ( )
397
386
. map ( |trait_ref| item. clone_and_push ( trait_ref, * span) )
398
- } )
399
- . collect ( ) ;
400
- debug ! ( "expand_trait_aliases: items={:?}" , items) ;
387
+ } ) ;
388
+ debug ! ( "expand_trait_aliases: items={:?}" , items. clone( ) ) ;
401
389
402
390
self . stack . extend ( items) ;
403
391
0 commit comments