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

Suggest use if import, using, or require is used instead #100140

Closed
bindsdev opened this issue Aug 4, 2022 · 9 comments · Fixed by #100167
Closed

Suggest use if import, using, or require is used instead #100140

bindsdev opened this issue Aug 4, 2022 · 9 comments · Fixed by #100167
Assignees
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

@bindsdev
Copy link
Contributor

bindsdev commented Aug 4, 2022

I was looking at namely issue #99751 when I thought about this. If work is being put into improving error messages when somebody uses a keyword that defines a function in another language, there should also be improved error messages if someone uses the incorrect directive to bring something into the scope of their module or namespace/

Given the following code: Playground Link

import std::mem;
using std::mem;
require std::mem;

The current output is:

error: expected one of `!` or `::`, found `std`
 --> src/main.rs:1:8
  |
1 | import std::mem;
  |        ^^^ expected one of `!` or `::`

error: could not compile `playground` due to previous error

The error message should preferably suggest the user to use the use directive to bring something into scope of their module.

@bindsdev bindsdev 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 Aug 4, 2022
@gimbling-away
Copy link
Contributor

@rustbot claim

@compiler-errors
Copy link
Member

For the record, on nightly, both import and using suggest using use. I'm sure it's not that difficult to add require.

@bindsdev
Copy link
Contributor Author

bindsdev commented Aug 4, 2022

For the record, on nightly, both import and using suggest using use. I'm sure it's not that difficult to add require.

ah. I was not aware of this. Less work to do then!

@gimbling-away
Copy link
Contributor

gimbling-away commented Aug 4, 2022

[Ignore this, just notes]

&& (self.token.is_ident_named(sym::import) || self.token.is_ident_named(sym::using))

repr_transparent,

@chenyukang
Copy link
Member

@gimbles
And also add include?
Rust may go tooooo friendly in diagnostic message 😊.
Do you mind that I make a PR for it? I'm a newbie in hacking Rust compiler.

@gimbling-away
Copy link
Contributor

gimbling-away commented Aug 5, 2022

Sure! The earlier message should clarify where the edits are needed to be made. Ain't nothing as a diagnostic too friendly. =)

@gimbling-away gimbling-away removed their assignment Aug 5, 2022
@gimbling-away
Copy link
Contributor

@chenyukang Remember to assign yourself using rustbot. 😄

Just a note for the future, usually if someone has already claimed an issue, it's not exactly common for someone else to fix it [aside from if the issue is abandoned by the claimee].

Since you're a newcomer here, I removed my assignment (and because I was working on another). However, you can find loads of easy issues with the E-Easy and/or E-Mentor tag for gaining experience.

A few resources that might be helpful ->
https://github.com/rust-lang/triagebot/wiki
https://github.com/rust-lang/rustc-dev-guide

Have fun hacking on Rust! 🦀 🤎

@chenyukang
Copy link
Member

@rustbot claim

@bindsdev
Copy link
Contributor Author

bindsdev commented Aug 5, 2022

@gimbles And also add include? Rust may go tooooo friendly in diagnostic message 😊. Do you mind that I make a PR for it? I'm a newbie in hacking Rust compiler.

Totally forgot about include! Good catch!

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.

4 participants