Skip to content

When encountering an incorrect trait bound referencing the current trait, suggest correct code #65985

Closed
@estebank

Description

@estebank

The following snippet is not correct:

trait Bar {}

trait Foo where Foo::Assoc: Bar {
    type Assoc;
}

But these three are:

trait Foo where Self::Assoc: Bar {
    type Assoc;
}
trait Foo where <Self as Foo>::Assoc: Bar {
    type Assoc;
}
trait Foo {
    type Assoc: Bar;
}

For the first we currently emit:

error[E0223]: ambiguous associated type
 --> file.rs:3:17
  |
3 | trait Foo where Foo::Assoc: Bar {
  |                 ^^^^^^^^^^ help: use fully-qualified syntax: `<Type as Foo>::Assoc`

but it should suggest one of the two valid snippets above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-papercutDiagnostics: An error or lint that needs small tweaks.P-lowLow priorityT-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