Skip to content

rust could suggest "use" if it finds something like "import ... crate::" #97788

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

Closed
matthiaskrgr opened this issue Jun 6, 2022 · 1 comment · Fixed by #97819
Closed

rust could suggest "use" if it finds something like "import ... crate::" #97788

matthiaskrgr opened this issue Jun 6, 2022 · 1 comment · Fixed by #97819
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jun 6, 2022

Given the following code:

mod a;
import crate::a::*;

fn main() {
    a();
    println!("Hello, world!");
}

The current output is:

error: expected one of `!` or `::`, found keyword `crate`
 --> src/main.rs:2:8
  |
2 | import crate::a::*;
  |        ^^^^^ expected one of `!` or `::`

Ideally the output should look like:

found keyword `import` did you instead intend to use `use` instead?
@matthiaskrgr matthiaskrgr 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. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. labels Jun 6, 2022
@compiler-errors
Copy link
Member

@rustbot claim

JohnTitor added a commit to JohnTitor/rust that referenced this issue Jun 8, 2022
…ywiser

Recover `import` instead of `use` in item

When we definitely don't have a macro invocation (i.e. when we don't have `import ::`), then it's more productive to parse `import` as if it was incorrectly mistaken for `use`.

Not sure if this needs to be a verbose suggestion, but it renders strangely when it's not verbose:
```
error: expected item, found `import`
 --> /home/michael/test.rs:1:1
  |
1 | import std::{io::{self, Write}, rc::Rc};
  | ^^^^^^ help: items are imported using the `use` keyword: `use`
```

Happy to change it to `span_suggestion` instead of `span_suggestion_verbose` though.

Fixes rust-lang#97788
@bors bors closed this as completed in a64a982 Jun 8, 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 D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. 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