I'm trying to understand how type constraints interact with associated types, and I've hit upon this case that I don't understand. I've read the RFC on unconstrained types in generic impls, but I can't see how this fits into the list of disallowed things. Intuitively, I would expect that for any type implementing Baz<T>, this code would specify exactly one unambiguous impl of Foo. Am I wrong about that, or can the compiler just not make that leap of logic? If not, why not?
trait Foo {
type Bar;
fn foo(&self) -> Self::Bar;
}
trait Baz<T> {
fn foo(&self) -> T;
}
impl<T, TBaz> Foo for TBaz
where
TBaz: Baz<T>
{
type Bar = T;
fn foo(&self) -> Self::Bar {
Baz::<T>::foo(self)
}
}
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> src/lib.rs:10:6
|
10 | impl<T, TBaz> Foo for TBaz
| ^ unconstrained type parameter
For more information about this error, try `rustc --explain E0207`.