@@ -107,7 +107,7 @@ pub fn elaborate_predicates<'cx, 'gcx, 'tcx>(
107
107
{
108
108
let mut visited = PredicateSet :: new ( tcx) ;
109
109
predicates. retain ( |pred| visited. insert ( pred) ) ;
110
- Elaborator { stack : predicates, visited : visited }
110
+ Elaborator { stack : predicates, visited }
111
111
}
112
112
113
113
impl < ' cx , ' gcx , ' tcx > Elaborator < ' cx , ' gcx , ' tcx > {
@@ -286,47 +286,49 @@ pub fn expand_trait_refs<'cx, 'gcx, 'tcx>(
286
286
let mut items: Vec < _ > =
287
287
trait_refs
288
288
. into_iter ( )
289
- . map ( |( tr , sp ) | TraitRefExpansionInfo {
290
- top_level_trait_ref : tr . clone ( ) ,
291
- top_level_span : sp ,
292
- trait_ref : tr ,
293
- span : sp ,
289
+ . map ( |( trait_ref , span ) | TraitRefExpansionInfo {
290
+ top_level_trait_ref : trait_ref . clone ( ) ,
291
+ top_level_span : span ,
292
+ trait_ref,
293
+ span,
294
294
} )
295
295
. collect ( ) ;
296
296
items. retain ( |item| visited. insert ( & item. trait_ref . to_predicate ( ) ) ) ;
297
- TraitRefExpander { stack : items, visited : visited , }
297
+ TraitRefExpander { stack : items, visited }
298
298
}
299
299
300
300
impl < ' cx , ' gcx , ' tcx > TraitRefExpander < ' cx , ' gcx , ' tcx > {
301
- // Returns `true` if `item` refers to a trait.
301
+ /// If `item` refers to a trait alias, adds the components of the trait alias to the stack,
302
+ /// and returns `false`.
303
+ /// If `item` refers to an ordinary trait, simply returns `true`.
302
304
fn push ( & mut self , item : & TraitRefExpansionInfo < ' tcx > ) -> bool {
303
305
let tcx = self . visited . tcx ;
304
306
305
307
if !tcx. is_trait_alias ( item. trait_ref . def_id ( ) ) {
306
308
return true ;
307
309
}
308
310
309
- // Get predicates declared on the trait.
311
+ // Get components of the trait alias .
310
312
let predicates = tcx. super_predicates_of ( item. trait_ref . def_id ( ) ) ;
311
313
312
314
let mut items: Vec < _ > = predicates. predicates
313
315
. iter ( )
314
316
. rev ( )
315
- . filter_map ( |( pred, sp ) | {
317
+ . filter_map ( |( pred, span ) | {
316
318
pred. subst_supertrait ( tcx, & item. trait_ref )
317
319
. to_opt_poly_trait_ref ( )
318
320
. map ( |trait_ref|
319
321
TraitRefExpansionInfo {
320
322
trait_ref,
321
- span : * sp ,
323
+ span : * span ,
322
324
..* item
323
325
}
324
326
)
325
327
} )
326
328
. collect ( ) ;
327
329
328
- debug ! ( "expand_trait_refs : trait_ref={:?} items={:?}" ,
329
- item. trait_ref, items) ;
330
+ debug ! ( "trait_ref_expander : trait_ref={:?} items={:?}" ,
331
+ item. trait_ref, items) ;
330
332
331
333
// Only keep those items that we haven't already seen.
332
334
items. retain ( |i| self . visited . insert ( & i. trait_ref . to_predicate ( ) ) ) ;
@@ -344,24 +346,17 @@ impl<'cx, 'gcx, 'tcx> Iterator for TraitRefExpander<'cx, 'gcx, 'tcx> {
344
346
}
345
347
346
348
fn next ( & mut self ) -> Option < TraitRefExpansionInfo < ' tcx > > {
347
- loop {
348
- let item = self . stack . pop ( ) ;
349
- match item {
350
- Some ( item) => {
351
- if self . push ( & item) {
352
- return Some ( item) ;
353
- }
354
- }
355
- None => {
356
- return None ;
357
- }
349
+ while let Some ( item) = self . stack . pop ( ) {
350
+ if self . push ( & item) {
351
+ return Some ( item) ;
358
352
}
359
353
}
354
+ None
360
355
}
361
356
}
362
357
363
358
///////////////////////////////////////////////////////////////////////////
364
- // Iterator over def-ids of supertraits
359
+ // Iterator over def-IDs of supertraits
365
360
///////////////////////////////////////////////////////////////////////////
366
361
367
362
pub struct SupertraitDefIds < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
0 commit comments