Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust complains about trait assoc type not being WF when we assume a triat impl (which is inherently WF) #54844

Closed
RalfJung opened this issue Oct 5, 2018 · 2 comments

Comments

@RalfJung
Copy link
Member

RalfJung commented Oct 5, 2018

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.

@rkarp
Copy link
Contributor

rkarp commented Oct 7, 2018

This looks like another duplicate of #24159.

@RalfJung
Copy link
Member Author

RalfJung commented Oct 7, 2018

It does indeed, thanks! Closing this.

@RalfJung RalfJung closed this as completed Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants