diagnostic codes / Types
E0203 mutability-required
A `const` binding was reassigned.
E0203mutability-requireddeclared const but reassigned; switch to let
| severity | error |
|---|---|
| band | Types |
| in the v0 bootstrap | emitted |
| explain | ralt explain E0203 |
`let` is mutable and `const` is not. The check runs on the left-hand side of every assignment and compound assignment, after the binding resolves, so it reports the binding's own name rather than the type of the value.
What it looks like
e0203.tp
use tier core; fn main() -> i32 { const k = 1; k = 2; return 0; }
ralt check e0203.tp e0203.tp:5:5: error: k is const and cannot be reassigned [E0203 mutability-required] declared const but reassigned; switch to let
What to do
- Change the declaration to `let` when the value is meant to change.
- Keep `const` and introduce a new binding for the second value.
- `const` beyond the function body is not accepted by the v0 parser; a file-level constant is E0101 today.
Why the code exists
A `const` says the reader never has to look for a second assignment. Enforcing it at the assignment is cheaper than making every reader scan the body.
What ralt explain says
ralt explain E0203 E0203 severity: error name: mutability-required hint: declared const but reassigned; switch to let
Related
- Statements /docs/reference/statements