Repository navigation
fix(infection): blank char literals before the rebinding scan (#10228) - #10294
Conversation
…n local initializers (#9774) Token-level scan: name in any earlier let pattern (destructuring, let-else, if/while let, same line), for pattern, closure parameter list, or match arm pattern region counts as a rebinding. Adds negatives with positive controls. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU
A struct pattern before a multiline => lost its bindings because the arm
region started after the last closing brace. Balance braces back to the
match's own opener so Some(Foo { n, .. }) stays in the region.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU
A closure parameter region containing braces or ';' was skipped wholesale,
so |Foo { n }| and |(a, n): (u8, [u8; 2])| escaped. Accept any region whose
brackets balance with no top-level ';'.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU
) A parenthesized or-pattern puts an internal pipe between the closure's pipes, so both fragments are unbalanced and were dropped. Reject a region only for a top-level ';'. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU
A ';' or '{' char literal ended a match-arm or let pattern region early, and
'"' opened a string. Add mask_rust_char_literals (lifetime-safe, offsets
preserved) and run it first in parameter_rebound_before only; the shared
mask and its pinned test are unchanged.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 8 minutes. View limit details
Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to mask Rust character literals before performing comment and string masking in the pattern-position rebinding scan. This prevents character literals like ';' or '{' from being incorrectly interpreted as punctuation that terminates pattern regions early. Feedback on the changes suggests optimizing the mask_rust_char_literals function to return a Cow<'_, str> and early-returning if the input does not contain any single quotes, which avoids unnecessary allocations.
There was a problem hiding this comment.
Decision
- Needs reviewer attention before upstream: findings remain.
Confirmed findings
- The helper's lifetime detection can misclassify a lifetime followed by a quoted token as a char literal and blank unrelated source.
Verification questions
- Confirm the helper claims support for Rust char escapes but does not distinguish a backslash escape from a literal backslash-containing character, so '\0' or '{' is not correctly masked as a one-character literal.
- Confirm the review packet contains no broad route inventory proving that other pattern-position rebinding entry points use this new pre-mask.
- Confirm the implementation scans bytes and computes UTF-8 widths, but the unit tests cover only one non-ASCII literal and do not assert byte-for-byte masking for multi-byte characters.
- Confirm the helper recognizes common escapes but its fallback treats every unknown backslash escape as exactly one escaped byte; Rust escape forms such as '\r' are covered by that rule, but malformed or specialized forms are not explicitly tested.
- Confirm the PR body claims lifetime safety, but the added regression tests exercise only the downstream pattern-position behavior and helper-specific examples, not a direct lifetime/label case through parameter_rebound_before.
Refuted
- The diff's new helper can only improve performance by avoiding allocations.; refuted because: It always allocates a byte vector and returns a new String, so the Cow suggestion remains a valid optimization request but is not a correctness finding.
- The new helper needs to be made public or duplicated across analysis modules.; refuted because: The implementation already lives in the Rust probe module and is re-exported through the established Rust and language module boundaries; the sole changed caller uses that route.
- The implementation allocates and copies the entire source for every scanned owner body.; refuted because: The change introduces an additional allocation, but the diff does not establish a material performance regression, and the previously raised allocation concern is not a correctness issue without measurement.
Parked follow-ups
- The helper allocates a full masked string for every parameter_rebound_before call; Cow would avoid copying only when no quote exists.
Evidence gaps
- Model proof intent was rejected by deterministic validation.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU
|
Head
Marking Ready with Generated by Claude Code |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Review of record at head
Merging at this head. Generated by Claude Code |
Summary
';'/'{'char literals as punctuation, ending a match-arm orletpattern region early, and'"'opened a string in the shared mask.mask_rust_char_literals(probes.rs) blanks the content of char and byte-char literals, keeping quotes and byte offsets, and borrows when the text has no quote. Lifetime-safe:'aand'outer:are left alone. It runs first inparameter_rebound_beforeonly;mask_rust_comments_and_stringsand its pinned test are unchanged.Some(n) if c == ';' =>andif let ('=', n) = pair). Negative experiment: removing the pre-mask fails the first pair.Source-of-truth Links
Proposal:
Spec: RIPR-SPEC-0158
ADR:
Plan item:
Governing issue or accepted claim: #10228
Acceptance delta (one sentence): A parameter bound before a char literal such as
';'or'{'in a match-arm orletpattern is still declined as rebound.Candidate Relationships
Candidate branch (GitHub PR head is authoritative after publication): claude/fix-10228-char-literal-mask
Stack parent or prerequisite PR (if any): none (#10154 merged)
Proof
cargo test -p ripr --lib classify::1709 passed;char_literal_maskunit test passes.cargo xtask precommitexit 0.🤖 Generated with Claude Code
https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU