Skip to main content

Errors

CodeError
E0221changing an element of an array, or a field of a struct, that isn't mut
E0222mut or imm before something that isn't an array, a struct, a tuple, a function or a type parameter
E0223an imm value that holds a mut one
E0224a mut field
E0225a named mutability that isn't the function's or impl's, or one its struct declares
E0232more mutability arguments than a struct declares
E0233a mutability parameter of an item that isn't a struct, a function or an impl
E0234a parameter of an impl, a type or a mutability, that isn't in its instance
[E0221] Error: cannot change an element of `xs`, which is `imm [i32]`; only a `mut` array can be changed
[E0221] Error: a field of an `imm Point` is changed here, but only a `mut` struct can be changed
[E0223] Error: an `imm Box[mut Point]` can't hold a `mut Point`: what an `imm` value holds can't be changed either

Passing or assigning a value of the wrong mutability is an ordinary type mismatch, which shows both:

[E0201] Error: expected `mut Point`, found `imm Point`

These can show up far from their cause: the push fails because of where the array was made, maybe much earlier. The error has a label for what expected mut, like a parameter, but not yet for where the Imm came from: the literal, the annotation, or the function whose result it is. For that, unification would have to remember the origin of Imm and Mut.