W0002
Variable that is never reassigned
WarningSafe fixA binding declared with let mut must be reassigned somewhere in its scope:
by =, by a compound assignment such as +=, or by a write to one of its
elements, and before a later let of the same name in the same scope shadows
it. When it never is, declare it with let.
W0011 warns in place of W0002 when a while condition that
nothing in the loop changes reads the binding.
W0014 warns in place of W0002 for a let mut that nothing reads.
W0002 still warns for an unread let mut in a function that no live code
uses, or when the program has an error.
Why
mut marks what can change
(ADR 0011). A let mut that
never changes would tell the reader to watch for a change that never comes,
so the keyword must always tell the truth.
Broken
fn main() {
let mut count = 3
print(count)
}
What sisu says
warning[W0002]: `count` is never reassigned --> W0002.sisu:2:13 | 2 | let mut count = 3 | ^^^^^ | help: declare it with `let` | 2 - let mut count = 3 2 + let count = 3 | sisu: 1 warning sisu: for more on a code, run `sisu explain <code>`: W0002
Fixed
fn main() {
let count = 3
print(count)
}
Related
- E0001: an assignment to a binding that cannot change.
Sisu