E0084
ErrorSafe fix
const inside a function
ErrorSafe fixA constant is declared at the top level, beside fn and class. Inside a function, a value that does not change is a let.
Why
A const names one value for the whole program, and its value is known at compile time. A let in a function already gives a name that cannot change, and its value may come from anything in scope. Replacing const with let is always right.
Broken
fn main() {
const limit = 100
print(limit)
}
What sisu says
error[E0084]: `const` is declared at the top level --> E0084.sisu:2:5 | 2 | const limit = 100 | ^^^^^ | help: use `let` | 2 - const limit = 100 2 + let limit = 100 | sisu: 1 error sisu: for more on a code, run `sisu explain <code>`: E0084
Fixed
fn main() {
let limit = 100
print(limit)
}
Related
- E0085: constant of a type that cannot be folded.
Sisu