Skip to content

E0207 when type parameter's associated type is used in Self. #64155

Open
@alex-ozdemir

Description

@alex-ozdemir

Not sure if this needs to be an error or not.

Per rustc --explain E0207, impl type parameter are acceptable if they appear in the Self type of the impl. Emphasis mine:

Any type parameter or lifetime parameter of an impl must meet at least one of
the following criteria:

  • it appears in the implementing type of the impl, e.g. impl<T> Foo<T>
  • for a trait impl, it appears in the implemented trait, e.g.
    impl<T> SomeTrait<T> for Foo
  • it is bound as an associated type, e.g. impl<T, U> SomeTrait for T where T: AnotherTrait<AssocType=U>

Rustc currently generates an error even if an associated type of the parameter appears in the Self type: playground link:

trait Field {}

trait Vector {
    type MyField: Field;
}

struct BaseFieldPrinter<F: Field>;

impl<V: Vector> BaseFieldPrinter<V::MyField> {
}

It seems like this doesn't need to be an error, but perhaps I'm missing something?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions