Why this fires¶
A destructuring assignment target — a tuple (a, b) = ... or a struct Struct { x, y } = ... — was used with something other than plain =, or had an invalid slot/field target. Compound assignment operators (+=, -=, ...) have no per-element meaning when the left-hand side is a whole pattern, and .. spread makes no sense as an assignment target (there's nothing to name).
fn f() {
var a = 1
var b = 2;
(a, b) += (1, 2)
// ^^ error[TE130]: destructuring assignment only supports `=`
// (compound ops have no per-element meaning)
}(The semicolon after var b = 2 matters here — without it, (a, b) on the next line parses as a call continuation of the previous statement instead of a new tuple-assignment target.)
struct P { x: int, y: int }
fn f(p: P) {
var x = 0
P { x, ..r } = p
// ^^^ error[TE130]: `..` is not allowed in an assignment target —
// name the fields you assign
}Fix it¶
1. Use plain =¶
fn f() {
var a = 1
var b = 2
(a, b) = (1, 2) // ok
}2. Don't spread into an assignment target¶
struct P { x: int, y: int }
fn f(p: P) {
var x = 0
var y = 0
P { x, y } = p // ok — name every field you assign
}See also¶
TE129— tuple-assignment value-count mismatch.TE005— type mismatch in a destructuring-assignment slot.- /docs/pattern-matching — destructuring assignment.