rust
rust copied to clipboard
Suggest `use` if `import`, `using`, or `require` is used instead
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.
@rustbot claim
For the record, on nightly, both import and using suggest using use. I'm sure it's not that difficult to add require.
For the record, on nightly, both
importandusingsuggest usinguse. I'm sure it's not that difficult to addrequire.
ah. I was not aware of this. Less work to do then!
[Ignore this, just notes]
https://github.com/rust-lang/rust/blob/caee496150a551fe1b9f77b3a58f7e66d54bc824/compiler/rustc_parse/src/parser/item.rs#L274
https://github.com/rust-lang/rust/blob/6f18f0a9d4548bc87afff1e4c0fe9081c35002c2/compiler/rustc_span/src/symbol.rs#L1172
@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.
Sure! The earlier message should clarify where the edits are needed to be made. Ain't nothing as a diagnostic too friendly. =)
@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! 🦀 🤎
@rustbot claim
@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!