Skip to content

Recover from missing crate or other scope resolution in use where appropriate #102711

Closed
@Rageking8

Description

@Rageking8

Given the following code: link

trait Trait {}

mod a {
    use Trait;
}

fn main() {}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0432]](https://doc.rust-lang.org/nightly/error-index.html#E0432): unresolved import `Trait`
 --> src/main.rs:4:9
  |
4 |     use Trait;
  |         ^^^^^ no external crate `Trait`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` due to previous error

Ideally the output can look something like this:

Compiling playground v0.0.1 (/playground)
error[[E0432]](https://doc.rust-lang.org/nightly/error-index.html#E0432): unresolved import `Trait`
 --> src/main.rs:4:9
  |
4 |     use Trait;
  |         ^^^^^ no external crate `Trait`
  |
help: add `crate::` to import trait `Trait`
  |
4 |     use crate::Trait;
  |         +++++++

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` due to previous error

This can also be extended to other items such as functions and variables. The help should only be emitted if an exact match exist in the parent scope and the scope resolution used is incorrect. Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-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