E0012 — Reassignment of an immutable binding

Only let mut bindings may be reassigned after initialization.


What triggers it

A let binding (without mut) appears on the left-hand side of a later assignment. Resilient bindings are immutable by default, so the compiler rejects the second write.

Minimal example

fn main() {
    let x = 1;
    x = 2;
}

Output:

scratch.rz:3:5: error[E0012]: cannot assign twice to immutable binding `x`
    x = 2;
    ^

Fix

Declare the binding mut if it’s genuinely reassigned, or introduce a new binding instead of reusing the name.

fn main() {
    let mut x = 1;
    x = 2;
}

Source

Emitted from the typechecker’s assignment-target check in resilient/src/typechecker.rs.