Skip to content

Commit 8d17c6a

Browse files
committed
Anonymize late bound regions on transitive bounds that define assoc type
1 parent fd09255 commit 8d17c6a

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

compiler/rustc_infer/src/traits/util.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -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
///////////////////////////////////////////////////////////////////////////
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// check-pass
2+
3+
pub struct LookupInternedStorage;
4+
5+
impl<Q> QueryStorageOps<Q> for LookupInternedStorage
6+
where
7+
Q: Query,
8+
for<'d> Q: QueryDb<'d>,
9+
{
10+
fn fmt_index(&self, db: &<Q as QueryDb<'_>>::DynDb) {
11+
<<Q as QueryDb<'_>>::DynDb as HasQueryGroup<Q::Group>>::group_storage(db);
12+
}
13+
}
14+
15+
pub trait HasQueryGroup<G> {
16+
fn group_storage(&self);
17+
}
18+
19+
pub trait QueryStorageOps<Q>
20+
where
21+
Q: Query,
22+
{
23+
fn fmt_index(&self, db: &<Q as QueryDb<'_>>::DynDb);
24+
}
25+
26+
pub trait QueryDb<'d> {
27+
type DynDb: HasQueryGroup<Self::Group> + 'd;
28+
type Group;
29+
}
30+
31+
pub trait Query: for<'d> QueryDb<'d> {}
32+
33+
fn main() {}

0 commit comments

Comments
 (0)