Trait bounds on associated types are not commuted to the rigid types when projection predicates are in environment #121670
Open
Description
cc @compiler-errors
I tried this code:
trait Foo {
type Bar: Qux;
}
trait Qux {
fn hello();
}
fn doesnt_work<T: Foo<Bar = U>, U>() {
T::Bar::hello(); // <~ `T::Bar` becomes `U`, for which we know nothing.
}
fn works<T: Foo>() {
T::Bar::hello();
}
I expected to see this happen: this should pass type check.
Instead, this happened: since T::Bar
is normalised to just U
, but there is no facts about U
except the projection predicate which is not used yet.
error[E0599]: no function or associated item named `hello` found for type parameter `U` in the current scope
--> src/lib.rs:10:13
|
9 | fn doesnt_work<U, T: Foo<Bar = U>>() {
| - function or associated item `hello` not found for this type parameter
10 | T::Bar::hello();
| ^^^^^ function or associated item not found in `U`
|
= help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `hello`, perhaps you need to restrict type parameter `U` with it:
|
9 | fn doesnt_work<U: Qux, T: Foo<Bar = U>>() {
| +++++
For more information about this error, try `rustc --explain E0599`.
Meta
It is known to be the case for a while including nightly and stable as of writing.
Backtrace
// Not an ICE
Activity