There is an issue #51774 for this. What I would like to understand is if this is something deeply rooted into the compiler, or if the compiler could be made to understand that the types can never overlap.
trait Test {
type MemberOf;
}
struct A;
struct B;
trait Get {
fn get(&self) -> &str;
}
/* impl<T: Test<MemberOf=A>> Get for T {
fn get(&self) -> &str {
"A"
}
} */
impl<T: Test<MemberOf=B>> Get for T {
fn get(&self) -> &str {
"B"
}
}
struct C;
impl Test for C {
type MemberOf = A;
}
fn main() {
println!("{}", C.get());
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0599]: the method `get` exists for struct `C`, but its trait bounds were not satisfied
--> src/main.rs:28:22
|
22 | struct C;
| --------
| |
| method `get` not found for this struct
| doesn't satisfy `<C as Test>::MemberOf = B`
| doesn't satisfy `C: Get`
...
28 | println!("{}", C.get());
| ^^^ method cannot be called on `C` due to unsatisfied trait bounds
|
note: trait bound `<C as Test>::MemberOf = B` was not satisfied
--> src/main.rs:16:14
|
16 | impl<T: Test<MemberOf=B>> Get for T {
| ^^^^^^^^^^ --- -
| |
| unsatisfied trait bound introduced here
For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground` due to previous error