Problem
Statement match currently rejects normal enum inspection code when one arm moves an ownership-tracked payload and other arms only read/copy, even when the carrier is not used after the match.
Example:
enum Result<T> {
Ok: { value: T },
Error: { message: str },
Pending
}
fn main() {
let result = Result<i32>::Error{ message = "failed" };
match result {
Result<i32>::Ok{ value = payload } => {
println(payload);
}
Result<i32>::Error{ message = message } => {
println(message);
}
Result<i32>::Pending => {
println(2);
}
}
}
Current diagnostic:
T0007 ownership state differs across control-flow paths
Expected behavior
This should compile when result is dead after the match. Only later use of result should require all reachable arms to leave a usable carrier state.
Required ownership model
- Keep current direct-carrier move rule for move-only payload fields.
- Keep rejecting move-only extraction from partial carriers: enum fields, indexes, pointees, temporaries, and other non-direct places.
- At a match join, distinguish values needed after the join from values that are dead after the join.
- Allow mixed arm ownership states only for carriers with no later use and no pending whole-carrier cleanup obligation.
- Preserve per-arm cleanup:
- moved/listed fields handled by arm body ownership;
- omitted owned fields dropped on consuming arms;
- untouched carriers cleaned normally on preserving arms;
- no duplicate whole-carrier cleanup.
- If the carrier is used after match, keep rejecting mixed ownership states or require reinitialization on consuming arms.
Polonius relationship
Rust's Polonius work is useful design input because it makes facts location-sensitive across CFG paths. This issue is not Polonius itself: it is ownership/drop-state convergence and cleanup planning for match.
Validation
- Add a positive runtime fixture where each arm prints/uses its payload and the carrier is not used after match.
- Add a negative fixture where the same mixed-state match is followed by
use(result).
- Add regression for explicit
_ discard of an owned field.
- Preserve existing positive fixtures for reinitialization and terminating consuming arms.
- Preserve partial-carrier move rejection fixtures.
- Add focused ownership tests proving cleanup is emitted exactly once per path.
Problem
Statement
matchcurrently rejects normal enum inspection code when one arm moves an ownership-tracked payload and other arms only read/copy, even when the carrier is not used after the match.Example:
Current diagnostic:
Expected behavior
This should compile when
resultis dead after the match. Only later use ofresultshould require all reachable arms to leave a usable carrier state.Required ownership model
Polonius relationship
Rust's Polonius work is useful design input because it makes facts location-sensitive across CFG paths. This issue is not Polonius itself: it is ownership/drop-state convergence and cleanup planning for
match.Validation
use(result)._discard of an owned field.