141. Lent values: five rules, lends only on fn signatures (2026-11-21)
- Decision. Every value is owned or lent (read or
mut); the mode is not part of the type. (1) Parameters are lent. (2) A value is lent if any part is: fields, closure captures, generator arguments;mut-lent if any part is. (3) A lent value lives until its last use in its block and is never stored or returned, except by a fn declaredlends. (4) Its sources stay lent while it lives. (5) Owned values move. Views are plain structs: thelends Sstruct marker from W4 is removed, so oneFilterowns or borrows by what built it. Alendsresult borrows every non-plain parameter;lends(xs)narrows it; bodies are checked against it. A generator value is a closure you walk: each walk reruns the body. No walk-once rule: walking amut-lent value twice is legal and linted. - Why. Ryan wanted signatures to say when a result borrows, without a second kind of struct. Rules 1-5 are 5.14 made precise; the walk-once error was dropped by Ryan in favour of a lint.
- Reverse. Restore
lends Son view structs, or make the second walk of amut-lent value an error (walk-once).