This code:
trait SayHello {
fn say_hello() { println!("hello") }
}
trait Foo {
type Hello: SayHello;
}
trait Bar: Foo {
type Hello: SayHello;
}
struct Generic<T>(T);
impl<T> Generic<T> where T: Bar<Hello = <T as Foo>::Hello> {
fn say_hello() {
T::Hello::say_hello()
}
}
returns this error:
error[E0221]: ambiguous associated type `Hello` in bounds of `T`
--> src/lib.rs:17:9
|
6 | type Hello: SayHello;
| --------------------- ambiguous `Hello` from `Foo`
...
10 | type Hello: SayHello;
| --------------------- ambiguous `Hello` from `Bar`
...
17 | T::Hello::say_hello()
| ^^^^^^^^^^^^^^^^^^^ ambiguous associated type `Hello`
|
help: use fully qualified syntax to disambiguate
|
17 | <T as Foo>::Hello()
| ^^^^^^^^^^^^^^^^^
help: use fully qualified syntax to disambiguate
|
17 | <T as Bar>::Hello()
| ^^^^^^^^^^^^^^^^^
But there shouldn't be any ambiguity. It's clearly stated that the Hello
associated type is the same in Foo
and bar
.
- Why is there an issue?
- Is there a way to make this logic work?