Conversation
|
HIR ty lowering was modified cc @fmease |
This comment was marked as outdated.
This comment was marked as outdated.
| if child_trait.def_id() == remaining_trait.def_id() | ||
| && self.tcx().anonymize_bound_vars(child_trait) | ||
| != self.tcx().anonymize_bound_vars(remaining_trait) | ||
| { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
This certainly isn't correct since it makes us start rejecting code like this:
//@ compile-flags: -Znext-solver
#![feature(supertrait_item_shadowing)]
trait A<'a> { type Ty; }
trait B: for<'a> A<'a> + A<'static> { type Ty; }
fn f<T: B>() {
let _: T::Ty; // PASS -> AMBIGUITY
}However, there should be no ambiguity under supertrait_item_shadowing as clearly the candidate <T as B>::Ty shadows both <T as A<'static>>::Ty and (pseudo) for<'a> <T as A<'a>>::Ty. It doesn't matter if the bound vars or the arguments mismatch. Identification by DefId is sufficient.
Similarly, this would make us reject code like below despite there being no ambiguity:
#![feature(supertrait_item_shadowing)]
trait A<D> { type Ty; }
trait B: A<i32> + A<()> { type Ty; }
fn f<T: B>() {
let _: T::Ty; // PASS -> AMBIGUITY
}There was a problem hiding this comment.
For reference, the fn analogue (which uses the collapse_candidates_to_subtrait_pick from method/probe.rs instead) continues to PASS under your PR meaning they now diverge in behavior:
//@ compile-flags: -Znext-solver
#![feature(supertrait_item_shadowing)]
trait A<'a> { fn f(); }
trait B: for<'a> A<'a> + A<'static> { fn f(); }
fn f<T: B>() {
let _ = T::f(); // PASS
}There was a problem hiding this comment.
So the root cause is somewhere else.
|
Reminder, once the PR becomes ready for a review, use |
the ICE caused by
collapse_candidates_to_subtrait_pickbecause it decided whether one trait was a supertrait just basing on thedef_idand ignoring the generic args.the fix approach adds an check using
anonymize_bound_varsbefore merging... if the check fails we return NONE to sign ambiguity and the existing ambiguity diagnostic (E0221) handles the rest...added 2 test and 1 .stderr
tested with ->
tests/ui/supertrait-shadowing/alpha-equivalent-duplicate-supertrait-binders.rsandtests/ui/supertrait-shadowing/ambiguous-duplicate-supertrait-binders.rsFixes #161547