Repository navigation
fix(rust): credit an unwrapped Ok tail after early Err returns - #7940
Conversation
A whole-value owner that returns `Ok(T { .. })` after an early
`return Err(..)` (or `Some(T { .. })` after `return None`) now gets the
same field credit as one that uses `?`, when the test compares
`owner(..).unwrap()` or `.expect("..")` with the bare literal. Other
early exits, a workspace-rebound `Err`/`None`, unwrap_or* and computed
expect messages still refuse (RIPR-SPEC-0225 decision 6, #6692).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
Summary by CodeRabbit
WalkthroughThe owner-pin classifier now allows whole-value field credit for ChangesWhole-value field credit
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
Code Review
This pull request implements RIPR-SPEC-0225 decision 6, which grants whole-value field credit to Rust owners returning Ok(T { .. }) or Some(T { .. }) despite early exits of the opposite variant (such as return Err(..) or return None). The analysis is updated to support tests comparing unwrapped values via .unwrap() or .expect("...") with bare literals, either inline or through a once-used local binding. The changes span classification logic in owner_pin.rs, spec documentation, unit tests, and fixture expectations. There are no review comments, and no additional feedback is provided.
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- WholeValueTail early_exit only feeds wrapper_may_be_rebound; equal-armed
matchof return expr for Option variants doesn't gate nested path-expr likeNone.(path tail). Unlikely but tightens with explicit PathExpr child check.
Verification questions
- Confirm test exercises Err/None rebinding by
fn Erranduse Ok as Err, satisfying claim-bound must-not-claim; missing: rebinding throughErras a local variable/type/const path.
Refuted
- An early 'return' that the masked-pass misses (inside "..." or //! comment) could let a non-Err/None exit survive returns_other_variant and credit a tail whose only Ok is not the literal.; refuted because: whole_value_tail parses the real source to rust-analyzer AST and collects ast::ReturnExpr from the parsed function body; the AST never contains tokens inside string literals or comments. The subsequent length check compares AST return count to whole_word_offsets(&masked, 'return') and requires equality; a masked-text-only 'return' makes masked count > AST count and returns None, refusing the pin.
Parked follow-ups
unwrapped_callrejects only"and\inside theexpect("...")message;\n/\t/\u{...}pass. Literal is still constant so panic semantics are preserved; spec text says 'plain string-literal message' without enumerating escapes.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Covers the #7940 review gaps: a std-rooted `use .. as Err` inside the owner, a rebound `None` beside a `Some` tail, and a positive control for the early-`Err` literal fixture. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
Main at a26f107 fails oracle_committed_rates_keep_labeled_and_unlabeled_cases (rows give 40/41). Same two lines as #7932; they no-op once it lands. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
Review of recordHead: Angles and findings
Negative controls (each fails the test)
Proof
Disposition: nothing blocking. Ready for the required check. Generated by Claude Code |
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- Out-of-scope lane: ub-active-view concerns (ResizableBuffer/ArrayBuffer/TypedArray resize, detach, transfer, stale length snapshots) do not apply to a pure Rust static analyzer PR with no JS/WASM/FFI surface touched.
Refuted
- An early return Err(..)/None could make owner(..).unwrap() read an active view backed by a partial/dead buffer (stale length, detached region).; refuted because: unwrap/expect panic on Err/None and yield the inner payload only on Ok/Some. returns_other_variant restricts early exits to the opposite variant and wrapper_may_be_rebound rejects any Err/None rebound (fn Err or use .. as Err), so the only values that flow into the unwrap are tail-literal Ok/Some. No resizable-buffer surface exists in this PR.
- wrapped_expected rewrap could over-credit when unwrap_wrapper is None; refuted because: The (true, None) arm returns false, refusing credit; the (false, _) arm leaves expected unchanged. The rewrap is only constructed when a WholeValueField gate yielded Some(wrapper), so the unreachable rewrap branch never executes outside the admitted path.
- returns_other_variant misses an Option
return None<...>path-expr with trailing tokens (e.g.,return None.unwrap_or(x)), letting a non-None exit slip through and credit an Option tail.; refuted because: In Option case,exit.expr()must be a PathExpr whose text equals exactly "None"; any trailing method call or qualifier renderspath.syntax().text() != "None", so the early exit refuses. A nestedreturn None.unwrap_or(..)therefore refuses outright rather than crediting — the inverse skip is the issue, not a credit leak.
Parked follow-ups
- Parked opposition note: equal-armed match of return expr for Option variants doesn't gate nested path-expr like
None.(path tail). Unlikely but could tighten with explicit PathExpr child check; out of memory-lifetime scope. - Parked: whether
assert_eq!(owner(..).unwrap_or(default_with_field_x), T{..})should ever credit when the default is the literal; out of decision 6 scope.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Resolves owner_pin.rs beside #7940's unwrapped Ok tail: the projection fallbacks stay on the rendered chain and unwrapped_direct follows it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019DhTE9QaZFAYeqtp9XRAGK
Summary
Before:
ledger-receipt-remainingread as a false gap.Inventory::shipreturnsOk(Receipt { .. })after two earlyreturn Err(..)exits. Its test doeslet receipt = inv.ship(..).unwrap(); assert_eq!(receipt, Receipt { .., remaining: 7 }), and both runtime mutants are killed. RIPR-SPEC-0225 refused any owner containingreturn, and it never read.unwrap()/.expect(..)of the owner call as the wrapped payload.After: that row reads
credited. An early exit is admitted only when it returns the variant the tail does not build:return Err(..)beside anOk(T { .. })tail, andreturn NonebesideSome(T { .. }). That is the same thing?already does, so everyOk/Somethe owner returns is the tail literal. The test may compareowner(..).unwrap()orowner(..).expect("plain literal")with the bare literalT { .. }, either inline or through a once-usedlet. The expected value is then checked asOk(T { .. })/Some(T { .. })against every existing gate.How:
whole_value_tail(owner_pin.rs) records anyreturns. It keeps the owner only when there is a wrapper, the AST return count equals the masked-text count, and every exit passesreturns_other_variant.WholeValueTail.early_exitnamesErr/Nonewhen there are early exits. Like the tail'sOk/Some, that constructor must not be rebound anywhere in the workspace (wrapper_may_be_rebound).WholeValueField::admitsreads anunwrapped_calloperand on both the direct and the bound path (bound_owner_initializer), then rewraps the expected literal.Swarm / Source Boundary
ripr-swarmSource-of-truth Links
Ok/Sometails and their early exits), extends example 3, and updates the implementation mapping.ledger-receipt-remaining, under rust: a field set in a hand-written Clone and checked by whole-value assert_eq reads weakly_exposed #6692.ledger-receipt-remainingmoves from gap to credited, and no other Rust corpus row moves.Candidate Relationships
Scope Classification
Ok/Someowners with other-variant early exits.Support-tier Impact
Proof
New test:
an_unwrapped_ok_tail_with_early_err_returns_pins_its_field.Ok(..);.unwrap()in both operand orders;.expect("parses");maybe(3).unwrap()besidereturn None.Ok(literal);unwrap_or_default;expect(&msg);let mut;return Ok(..);return parse(..);return Err(..).or(..);return Some(..);return maybe(..);return FALLBACK;Errrebound byfn Error byuse std::result::Result::Ok as Err.Negative controls (each makes the test fail):
returns_other_variantalways true;expectliteral check removed;Nonepath check loosened;Err/Nonerebinding check dropped.The review of record is in the PR comments.
Claim Boundary
Err/Noneexit no longer blocks whole-value credit for an unwrapped owner call.unwrap_or*, computedexpectmessages, or raw-string messages (these are conservative misses).🤖 Generated with Claude Code
https://claude.ai/code/session_01U7GbrVC98fTYnLnhe3vhFM
Generated by Claude Code