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

hint for global use of let instead of const or static #83265

Closed
hkBst opened this issue Mar 18, 2021 · 3 comments
Closed

hint for global use of let instead of const or static #83265

hkBst opened this issue Mar 18, 2021 · 3 comments
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

@hkBst
Copy link
Contributor

hkBst commented Mar 18, 2021

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ffbf1151b3ceaee128b58616565c8774

let global_variable = 0;

The current output is:

error: expected item, found keyword `let`
 --> src/lib.rs:1:1
  |
1 | let global_variable = 0;
  | ^^^ expected item

Ideally the output should look like:

Something about Rust not supporting this syntax and to try to use either static or const instead.

Since this is the syntax for writing local variables, I often try to use this same syntax at global scope and get an unhelpful error message.

@hkBst hkBst 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 Mar 18, 2021
@hkBst
Copy link
Contributor Author

hkBst commented Dec 6, 2021

Proof that I am not alone in this: https://users.rust-lang.org/t/a-friendly-challenge-for-rust/23197/12

@kornelski
Copy link
Contributor

@hkBst
Copy link
Contributor Author

hkBst commented Mar 21, 2023

It seems this got fixed. Current message is:

error: expected item, found keyword `let`
 --> src/lib.rs:1:1
  |
1 | let global_variable = 0;
  | ^^^ consider using `const` or `static` instead of `let` for global variables

@hkBst hkBst closed this as completed Mar 21, 2023
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

No branches or pull requests

2 participants