Skip to content

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

Description

@RalfJung

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.

Activity

  1. rkarp commented on Oct 7, 2018

    @rkarp
    Contributor

    This looks like another duplicate of #24159.

  2. RalfJung commented on Oct 7, 2018

    @RalfJung
    MemberAuthor

    It does indeed, thanks! Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions