Skip to content

Search in associated items when type cannot be found #73321

Open
@estebank

Description

@estebank

Given the following code:

pub trait Foo {
type A;
fn boo(&self) -> <Self as Foo>::A;
}
fn foo2<I: Foo>(x: I) {
let _: A = x.boo(); //~ ERROR cannot find type `A` in this scope
}

we currently show

error[E0412]: cannot find type `A` in this scope
--> $DIR/associated-types-eq-1.rs:10:12
|
LL | fn foo2<I: Foo>(x: I) {
| - similarly named type parameter `I` defined here
LL | let _: A = x.boo();
| ^ help: a type parameter with a similar name exists: `I`

But the typo checks should also look at the associated types of all the locally accessible types and provide a reasonable suggestion.

In this specific case of assignment, we could also look at the type of boo for an appropriate type to supply.

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.D-papercutDiagnostics: An error or lint that needs small tweaks.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