@@ -292,26 +292,33 @@ pub fn transitive_bounds_that_define_assoc_type<'tcx>(
292
292
tcx : TyCtxt < ' tcx > ,
293
293
bounds : impl Iterator < Item = ty:: PolyTraitRef < ' tcx > > ,
294
294
assoc_name : Ident ,
295
- ) -> FxIndexSet < ty:: PolyTraitRef < ' tcx > > {
295
+ ) -> impl Iterator < Item = ty:: PolyTraitRef < ' tcx > > {
296
296
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
+ }
309
314
}
315
+
316
+ return Some ( trait_ref) ;
310
317
}
311
318
}
312
- }
313
319
314
- trait_refs
320
+ return None ;
321
+ } )
315
322
}
316
323
317
324
///////////////////////////////////////////////////////////////////////////
0 commit comments