@@ -107,7 +107,7 @@ pub fn elaborate_predicates<'cx, 'gcx, 'tcx>(
107107{
108108 let mut visited = PredicateSet :: new ( tcx) ;
109109 predicates. retain ( |pred| visited. insert ( pred) ) ;
110- Elaborator { stack : predicates, visited : visited }
110+ Elaborator { stack : predicates, visited }
111111}
112112
113113impl < ' cx , ' gcx , ' tcx > Elaborator < ' cx , ' gcx , ' tcx > {
@@ -286,47 +286,49 @@ pub fn expand_trait_refs<'cx, 'gcx, 'tcx>(
286286 let mut items: Vec < _ > =
287287 trait_refs
288288 . 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,
294294 } )
295295 . collect ( ) ;
296296 items. retain ( |item| visited. insert ( & item. trait_ref . to_predicate ( ) ) ) ;
297- TraitRefExpander { stack : items, visited : visited , }
297+ TraitRefExpander { stack : items, visited }
298298}
299299
300300impl < ' 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`.
302304 fn push ( & mut self , item : & TraitRefExpansionInfo < ' tcx > ) -> bool {
303305 let tcx = self . visited . tcx ;
304306
305307 if !tcx. is_trait_alias ( item. trait_ref . def_id ( ) ) {
306308 return true ;
307309 }
308310
309- // Get predicates declared on the trait.
311+ // Get components of the trait alias .
310312 let predicates = tcx. super_predicates_of ( item. trait_ref . def_id ( ) ) ;
311313
312314 let mut items: Vec < _ > = predicates. predicates
313315 . iter ( )
314316 . rev ( )
315- . filter_map ( |( pred, sp ) | {
317+ . filter_map ( |( pred, span ) | {
316318 pred. subst_supertrait ( tcx, & item. trait_ref )
317319 . to_opt_poly_trait_ref ( )
318320 . map ( |trait_ref|
319321 TraitRefExpansionInfo {
320322 trait_ref,
321- span : * sp ,
323+ span : * span ,
322324 ..* item
323325 }
324326 )
325327 } )
326328 . collect ( ) ;
327329
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) ;
330332
331333 // Only keep those items that we haven't already seen.
332334 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> {
344346 }
345347
346348 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) ;
358352 }
359353 }
354+ None
360355 }
361356}
362357
363358///////////////////////////////////////////////////////////////////////////
364- // Iterator over def-ids of supertraits
359+ // Iterator over def-IDs of supertraits
365360///////////////////////////////////////////////////////////////////////////
366361
367362pub struct SupertraitDefIds < ' a , ' gcx : ' a +' tcx , ' tcx : ' a > {
0 commit comments