Skip to content

Commit

Permalink
Ignore non-self item bounds for rigid projections
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 20, 2024
1 parent a128516 commit e6b64c6
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Expand Up @@ -1620,16 +1620,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
for bound in
self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args)
{
// HACK: On subsequent recursions, we only care about bounds that don't
// HACK: In the initial recursion, we only care about bounds for the
// `self_ty`. On subsequent recursions, we care about bounds that don't
// share the same type as `self_ty`. This is because for truly rigid
// projections, we will never be able to equate, e.g. `<T as Tr>::A`
// with `<<T as Tr>::A as Tr>::A`.
if in_parent_alias_type {
match bound.kind().skip_binder() {
ty::ClauseKind::Trait(tr) if tr.self_ty() == self_ty => continue,
ty::ClauseKind::Projection(p) if p.self_ty() == self_ty => continue,
_ => {}
match bound.kind().skip_binder() {
ty::ClauseKind::Trait(tr)
if (tr.self_ty() == self_ty) ^ !in_parent_alias_type =>
{
continue;
}
ty::ClauseKind::Projection(p)
if (p.self_ty() == self_ty) ^ !in_parent_alias_type =>
{
continue;
}
_ => {}
}

for_each(self, bound, idx)?;
Expand Down

0 comments on commit e6b64c6

Please sign in to comment.