Skip to content

Suggestion to fix clashing trait and generic names is incorrect when desired trait comes from module #109950

Open
@schuelermine

Description

@schuelermine

Code

use crate::a::B;

mod a {
    pub trait B {}
}

struct C<B: B>(B);

Current output

error[E0404]: expected trait, found type parameter `B`
 --> src/lib.rs:7:13
  |
1 | use crate::a::B;
  |               - you might have meant to refer to this trait
...
7 | struct C<B: B>(B);
  |          -  ^ not a trait
  |          |
  |          found this type parameter
  |
help: consider importing this trait instead
  |
1 | use crate::a::B;
  |

Desired output

error[E0404]: expected trait, found type parameter `B`
 --> src/lib.rs:7:13
  |
1 | use crate::a::B;
  |               - you might have meant to refer to this trait
...
7 | struct C<B: B>(B);
  |          -  ^ not a trait
  |          |
  |          found this type parameter
  |

Rationale and extra context

The import is already there. Ideally it should tell you that the import is being shadowed by the generic, but barring that, it definitely shouldn’t suggest adding a useless line of code that already exists and only creates more errors.

Other cases

No response

Anything else?

This happens on stable and nightly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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