Closed
Description
Trait bounds on associated types seem to be required, not implied, when the trait in question mentions an associated type on a type parameter.
Concretely, this code (or playground) produces an error:
trait Foo { type FooT: Foo; }
impl Foo for () { type FooT = (); }
trait Bar<T: Foo> { type BarT: Bar<T::FooT>; }
impl Bar<()> for () { type BarT = (); }
fn test<C: Bar<()>>() { }
error[E0277]: the trait bound `<C as Bar<()>>::BarT: Bar<()>` is not satisfied
--> src/main.rs:6:1
|
6 | fn test<C: Bar<()>>() { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar<()>` is not implemented for `<C as Bar<()>>::BarT`
|
= help: consider adding a `where <C as Bar<()>>::BarT: Bar<()>` bound
= note: required by `Bar`
despite the C::BarT: Bar<()>
bound being required by the definition of Bar
itself, and in fact this means that the trait Bar<T>
can never be mentioned.
This similar example (playground) that doesn't use an associated type in the trait parameter compiles:
trait Foo { type FooT: Foo; }
impl Foo for () { type FooT = (); }
trait Bar<T: Foo> { type BarT: Bar<T>; }
impl Bar<()> for () { type BarT = (); }
fn test<C: Bar<()>>() { }
while this version (playground), which uses a third trait to avoid the self-reference, does not:
trait Foo { type FooT: Foo; }
impl Foo for () { type FooT = (); }
trait Bar<T: Foo> { type BarT: Baz<T::FooT>; }
impl Bar<()> for () { type BarT = (); }
trait Baz<T: Foo> { }
impl Baz<()> for () { }
fn test<C: Bar<()>>() { }
Is this just a missing normalization step?