Skip to content

Commit 38df5bd

Browse files
Ignore own item bounds in parent alias types in for_each_item_bound
1 parent 899c895 commit 38df5bd

File tree

1 file changed

+16
-0
lines changed
  • compiler/rustc_trait_selection/src/traits/select

1 file changed

+16
-0
lines changed

compiler/rustc_trait_selection/src/traits/select/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16051605
on_ambiguity: impl FnOnce(),
16061606
) -> ControlFlow<T, ()> {
16071607
let mut idx = 0;
1608+
let mut in_parent_alias_type = false;
1609+
16081610
loop {
16091611
let (kind, alias_ty) = match *self_ty.kind() {
16101612
ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty),
@@ -1618,6 +1620,18 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16181620
for bound in
16191621
self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args)
16201622
{
1623+
// HACK: On subsequent recursions, we only care about bounds that don't
1624+
// share the same type as `self_ty`. This is because for truly rigid
1625+
// projections, we will never be able to equate, e.g. `<T as Tr>::A`
1626+
// with `<<T as Tr>::A as Tr>::A`.
1627+
if in_parent_alias_type {
1628+
match bound.kind().skip_binder() {
1629+
ty::ClauseKind::Trait(tr) if tr.self_ty() == self_ty => continue,
1630+
ty::ClauseKind::Projection(p) if p.self_ty() == self_ty => continue,
1631+
_ => {}
1632+
}
1633+
}
1634+
16211635
for_each(self, bound, idx)?;
16221636
idx += 1;
16231637
}
@@ -1627,6 +1641,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16271641
} else {
16281642
return ControlFlow::Continue(());
16291643
}
1644+
1645+
in_parent_alias_type = true;
16301646
}
16311647
}
16321648

0 commit comments

Comments
 (0)