Skip to content

Wrong "possible better candidate is found in another module" suggestion #42944

Closed
@est31

Description

@est31

For this code:

mod foo {
    pub struct B(());
}
mod bar {
    use foo::B;
    fn foo() {
        B(());
    }
}

You get the following error message:

error[E0423]: expected function, found struct `B`
 --> <anon>:7:9
  |
7 |         B(());
  |         ^
  |         |
  |         did you mean `B { /* fields */ }`?
  |         constructor is not visible here due to private fields
  |
help: possible better candidate is found in another module, you can import it into scope
  | use foo::B;

The suggestion may be excused to be not 100% perfect, but here it suggests to add an use statement despite that same item being imported already. What I want is this exactly: that it removes stuff from the suggestion list that is already being imported.

Note that changing the glob import to a non glob one doesn't change anything.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`A-visibilityArea: Visibility / privacyC-enhancementCategory: An issue proposing an enhancement or a PR with one.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions