Consider this code:
trait Map<K, V> {}
trait Machine {
type Tag;
type MyMap: Map<usize, Self::Tag> + Default;
}
struct Context<M: Machine>(M::MyMap);
impl<M: Machine<Tag = ()>> Context<M> {
fn new() -> Self {
Context(Default::default())
}
}
It fails to compile with
error[E0277]: the trait bound `<M as Machine>::MyMap: Map<usize, ()>` is not satisfied
--> src/lib.rs:10:1
|
10 | / impl<M: Machine<Tag = ()>> Context<M> {
11 | | fn new() -> Self {
12 | | Context(Default::default())
13 | | }
14 | | }
| |_^ the trait `Map<usize, ()>` is not implemented for `<M as Machine>::MyMap`
|
= help: consider adding a `where <M as Machine>::MyMap: Map<usize, ()>` bound
note: required by `Machine`
--> src/lib.rs:3:1
|
3 | trait Machine {
| ^^^^^^^^^^^^^
error[E0277]: the trait bound `<M as Machine>::MyMap: Map<usize, ()>` is not satisfied
--> src/lib.rs:11:5
|
11 | / fn new() -> Self {
12 | | Context(Default::default())
13 | | }
| |_____^ the trait `Map<usize, ()>` is not implemented for `<M as Machine>::MyMap`
|
= help: consider adding a `where <M as Machine>::MyMap: Map<usize, ()>` bound
note: required by `Machine`
--> src/lib.rs:3:1
|
3 | trait Machine {
| ^^^^^^^^^^^^^
error: aborting due to 2 previous errors
But that is strange, because the M: Machine impl must be well-formed, so of course that bound is met.
Consider this code:
It fails to compile with
But that is strange, because the
M: Machineimpl must be well-formed, so of course that bound is met.