Skip to content

Improve the help message for the error on using fully qualified syntax for nested associated types #59225

Open
@salmans

Description

@salmans

Here is a small example to reproduce the error and its help message:

trait A {
    type Item;
}

trait B {
    type Item: A;

    fn trait_fn(x: Self::Item::Item);
}

Then I get the following error:

error[E0223]: ambiguous associated type
 --> src/main.rs:8:20
  |
8 |     fn trait_fn(x: Self::Item::Item);
  |                    ^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<<Self as B>::Item as Trait>::Item`

It looks like the word "Trait" in <<Self as B>::Item as Trait>::Item should be replaced with the trait name A so that the suggested expression compiles:
help: use fully-qualified syntax: <<Self as B>::Item as A>::Item.

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`C-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