Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Rageking8 opened this issue Oct 5, 2022 · 1 comment · Fixed by #102876
Closed

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

Rageking8 opened this issue Oct 5, 2022 · 1 comment · Fixed by #102876
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rageking8
Copy link
Contributor

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.

@Rageking8 Rageking8 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 5, 2022
@Noratrieb
Copy link
Member

Noratrieb commented Oct 6, 2022

We already have similar logic for normal uses of items

trait Trait {}

mod a {
    impl Trait for () {}
}

fn main() {}
error[E0405]): cannot find trait `Trait` in this scope
 --> src/main.rs:4:10
  |
4 |     impl Trait for () {}
  |          ^^^^^ not found in this scope
  |
help: consider importing one of these items
  |
4 |     use crate::Trait;
  |
4 |     use traitobject::Trait;
  |

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 10, 2022
…1-dead

suggest candidates for unresolved import

Currently we prompt suggestion of candidates(help notes of `use xxx::yyy`) for names which cannot be resolved, but we don't do that for import statements themselves that couldn't be resolved. It seems reasonable to add candidate help information for these statements as well.
Fixes rust-lang#102711
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Oct 10, 2022
…1-dead

suggest candidates for unresolved import

Currently we prompt suggestion of candidates(help notes of `use xxx::yyy`) for names which cannot be resolved, but we don't do that for import statements themselves that couldn't be resolved. It seems reasonable to add candidate help information for these statements as well.
Fixes rust-lang#102711
@bors bors closed this as completed in 0bd1cba Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants