Expand description
Native ownership analysis for use-after-move detection.
Lightweight data-flow analysis that catches use-after-move at check-time
(milliseconds), before Rust compilation. This pass tracks Owned, Moved,
and Borrowed states through control flow.
Collections have value semantics in every tier: a call’s plain argument and
Let b be a each receive a copy, and the caller’s value stays usable. Only
GIVING moves — the Give x to y. statement, and give x as a call argument
(Call consume with give data.), which the backend emits as a real move.
§State Transitions
Let x be value
│
▼
[Owned] ── f(x) · Let y be x ──▶ [Owned]
/ \
Give x Show x
… with give x │
│ ▼
▼ [Borrowed]
[Moved] │
│ use x? ✓
use x?
│
ERROR: use-after-move§Control Flow Awareness
The checker handles branches and loops by merging states:
Movedon one path +Ownedon another =MaybeMoved, remembering whether a branch or a loop made the move uncertain- A loop may run no pass at all, so its body’s moves merge with the state before it
- Using a
MaybeMovedvariable produces an error, wherever it is read: anIforWhilecondition, the collection aRepeatwalks and the value anInspectexamines included
§The Program as Written
Ownership is a property of the program its author wrote, so every entry point runs this
checker on the freshly-parsed statements, before any rewrite. Once x is a known constant,
the optimizer’s propagation turns Give x to p. into Give 5 to p. and Show x. into
Show 5., and folding flattens a constant If into its body: a checker fed that program
would pass a use after a possible move, or call a possible move certain.
§Example
Let x be 5.
Give x to y.
Show x to show. ← Error: Cannot use 'x' after giving it awayStructs§
- Ownership
Checker - Ownership checker - tracks variable states through control flow
- Ownership
Error - Error type for ownership violations
- Ownership
Finding - One ownership finding with its statement coordinates: the top-level
statement that ERRED, and (when known) the one that CAUSED it by moving
the variable — both map 1:1 onto
Parser::stmt_spans()— plus the exact statements, nested ones included, forParser::nested_stmt_spans():trailis the erring statement and each one around it, innermost first, andcauseis the statement that gave the value away.
Enums§
- Maybe
Given In - Where a value may have been given away: the construct whose paths disagree about it.
- Ownership
Error Kind - VarState
- Ownership state for a variable