Design decisions

128. Moves, overlapping mut places, and map defaults (2026-11-21)

  • Decision. Returning a container is always O(1): returns move, never copy. let b = a on a heap value (List, Map, Str, structs holding them) is a move when it is a's last use and otherwise an error whose fix is a.clone(). Using a moved-from variable is a compile error; moving out of a place that stays alive is x.take(), which leaves it empty. Functions never take ownership of an argument: parameters are lends, mut parameters may mutate (and absorb(mut other) may drain) but the caller keeps the variable.
  • Decision. Two mut places in one container in the same call (f(mut a[i], mut a[j])) are a compile error unless the compiler proves them distinct. Changing a container's length while a place in it is lent (let x = mut xs[i] then xs.push(...)) is a compile error, the same rule as overlapping slices (E0602). Both are "for now": a runtime distinctness check can relax the first later.
  • Decision. m[k] += 1 (any compound assignment into a map) inserts the value type's default for a missing k first. A plain read of a missing key is none for Map and the default for Counter.
  • Why. Costs stay visible (no silent deep copy), invalidation and aliasing bugs can't be written, and counting reads like the idea.
  • Reverse. Implicit copies for let b = a; runtime overlap checks; m[k] += 1 on a missing key as an error.
  • Status. Accepted (Ryan, 2026-11-21). Audit current checker behaviour against each rule; implement the gaps with compile-fail tests.