diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 8a1035707fe45..87684c2715f4e 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -292,26 +292,33 @@ pub fn transitive_bounds_that_define_assoc_type<'tcx>( tcx: TyCtxt<'tcx>, bounds: impl Iterator>, assoc_name: Ident, -) -> FxIndexSet> { +) -> impl Iterator> { let mut stack: Vec<_> = bounds.collect(); - let mut trait_refs = FxIndexSet::default(); - - while let Some(trait_ref) = stack.pop() { - if trait_refs.insert(trait_ref) { - let super_predicates = - tcx.super_predicates_that_define_assoc_type((trait_ref.def_id(), Some(assoc_name))); - for (super_predicate, _) in super_predicates.predicates { - let bound_predicate = super_predicate.kind(); - let subst_predicate = super_predicate - .subst_supertrait(tcx, &bound_predicate.rebind(trait_ref.skip_binder())); - if let Some(binder) = subst_predicate.to_opt_poly_trait_ref() { - stack.push(binder.value); + let mut visited = FxIndexSet::default(); + + std::iter::from_fn(move || { + while let Some(trait_ref) = stack.pop() { + let anon_trait_ref = tcx.anonymize_late_bound_regions(trait_ref); + if visited.insert(anon_trait_ref) { + let super_predicates = tcx.super_predicates_that_define_assoc_type(( + trait_ref.def_id(), + Some(assoc_name), + )); + for (super_predicate, _) in super_predicates.predicates { + let bound_predicate = super_predicate.kind(); + let subst_predicate = super_predicate + .subst_supertrait(tcx, &bound_predicate.rebind(trait_ref.skip_binder())); + if let Some(binder) = subst_predicate.to_opt_poly_trait_ref() { + stack.push(binder.value); + } } + + return Some(trait_ref); } } - } - trait_refs + return None; + }) } /////////////////////////////////////////////////////////////////////////// diff --git a/src/test/ui/associated-type-bounds/traits-assoc-anonymized.rs b/src/test/ui/associated-type-bounds/traits-assoc-anonymized.rs new file mode 100644 index 0000000000000..a9d6eed810a6b --- /dev/null +++ b/src/test/ui/associated-type-bounds/traits-assoc-anonymized.rs @@ -0,0 +1,33 @@ +// check-pass + +pub struct LookupInternedStorage; + +impl QueryStorageOps for LookupInternedStorage +where + Q: Query, + for<'d> Q: QueryDb<'d>, +{ + fn fmt_index(&self, db: &>::DynDb) { + <>::DynDb as HasQueryGroup>::group_storage(db); + } +} + +pub trait HasQueryGroup { + fn group_storage(&self); +} + +pub trait QueryStorageOps +where + Q: Query, +{ + fn fmt_index(&self, db: &>::DynDb); +} + +pub trait QueryDb<'d> { + type DynDb: HasQueryGroup + 'd; + type Group; +} + +pub trait Query: for<'d> QueryDb<'d> {} + +fn main() {}