@@ -292,26 +292,33 @@ pub fn transitive_bounds_that_define_assoc_type<'tcx>(
292292    tcx :  TyCtxt < ' tcx > , 
293293    bounds :  impl  Iterator < Item  = ty:: PolyTraitRef < ' tcx > > , 
294294    assoc_name :  Ident , 
295- )  -> FxIndexSet < ty:: PolyTraitRef < ' tcx > >  { 
295+ )  -> impl   Iterator < Item  =  ty:: PolyTraitRef < ' tcx > >  { 
296296    let  mut  stack:  Vec < _ >  = bounds. collect ( ) ; 
297-     let  mut  trait_refs = FxIndexSet :: default ( ) ; 
298- 
299-     while  let  Some ( trait_ref)  = stack. pop ( )  { 
300-         if  trait_refs. insert ( trait_ref)  { 
301-             let  super_predicates =
302-                 tcx. super_predicates_that_define_assoc_type ( ( trait_ref. def_id ( ) ,  Some ( assoc_name) ) ) ; 
303-             for  ( super_predicate,  _)  in  super_predicates. predicates  { 
304-                 let  bound_predicate = super_predicate. kind ( ) ; 
305-                 let  subst_predicate = super_predicate
306-                     . subst_supertrait ( tcx,  & bound_predicate. rebind ( trait_ref. skip_binder ( ) ) ) ; 
307-                 if  let  Some ( binder)  = subst_predicate. to_opt_poly_trait_ref ( )  { 
308-                     stack. push ( binder. value ) ; 
297+     let  mut  visited = FxIndexSet :: default ( ) ; 
298+ 
299+     std:: iter:: from_fn ( move  || { 
300+         while  let  Some ( trait_ref)  = stack. pop ( )  { 
301+             let  anon_trait_ref = tcx. anonymize_late_bound_regions ( trait_ref) ; 
302+             if  visited. insert ( anon_trait_ref)  { 
303+                 let  super_predicates = tcx. super_predicates_that_define_assoc_type ( ( 
304+                     trait_ref. def_id ( ) , 
305+                     Some ( assoc_name) , 
306+                 ) ) ; 
307+                 for  ( super_predicate,  _)  in  super_predicates. predicates  { 
308+                     let  bound_predicate = super_predicate. kind ( ) ; 
309+                     let  subst_predicate = super_predicate
310+                         . subst_supertrait ( tcx,  & bound_predicate. rebind ( trait_ref. skip_binder ( ) ) ) ; 
311+                     if  let  Some ( binder)  = subst_predicate. to_opt_poly_trait_ref ( )  { 
312+                         stack. push ( binder. value ) ; 
313+                     } 
309314                } 
315+ 
316+                 return  Some ( trait_ref) ; 
310317            } 
311318        } 
312-     } 
313319
314-     trait_refs
320+         return  None ; 
321+     } ) 
315322} 
316323
317324/////////////////////////////////////////////////////////////////////////// 
0 commit comments