Skip to content

Suggest paths on "unresolved import" #47450

@oberien

Description

@oberien

Let's assume the following code:

mod foo {
    #[derive(Debug)]
    pub struct Foo;
}

mod bar {}

use bar::Foo;

fn main() {
    println!("{:?}", Foo);
}

If I leave out the use statement, rust provides me with helpful suggestions:

9 |     println!("{:?}", Foo);
  |                      ^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
  |
1 | use foo::Foo;
  |

If I have the incorrect use statement, though, rust just states that it's incorrect:

  |
8 | use bar::Foo;
  |     ^^^^^^^^ no `Foo` in `bar`

I'd like to suggest a message along the lines of help: did you mean one of these imports from other modules?.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-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