E0424: Invalid assignment target
| Code | Category | Stability |
|---|---|---|
E0424 | Struct and enum | Permanent |
Explanation
An assignment target is syntactically accepted but does not resolve to a writable place. Writable roots include let mut locals, inout parameters, and receivers declared mut self or inout self within their method body; field and index projections from those roots remain places. An exclusive place-returning accessor over writable storage may also form or continue a place. Bare self, borrow self, ordinary values, and shared accessor results are not writable roots. Other diagnostics separately report places whose roots exist but lack permission to mutate.
Likely cause
The left-hand side is a temporary value, a value-returning or shared method call, or an accessor chain that does not yield an exclusive place. Assign through a mutable local, an inout parameter, an appropriately mutable receiver, a field or array element rooted in one, or an exclusive accessor that denotes writable storage.
Examples
Assign through a value-returning method
struct Counter {
value: i32,
fn current(self) -> i32 { self.value }
}
fn main() {
let mut counter = Counter { value: 0 };
counter.current() = 42;
}
Assign through a mutable field place
struct Counter { value: i32 }
fn main() -> i32 {
let mut counter = Counter { value: 0 };
counter.value = 42;
counter.value
}