Skip to content

fix(infection): blank char literals before the rebinding scan (#10228) - #10294

Merged
EffortlessSteven merged 8 commits into
mainfrom
claude/fix-10228-char-literal-mask
Oct 25, 2026
Merged

EffortlessSteven merged 8 commits into
mainfrom
claude/fix-10228-char-literal-mask

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • The pattern-position rebinding scan from fix(infection): fail closed on destructuring/pattern rebinding of parameters in local initializers (#9774) #10154 read ';' / '{' char literals as punctuation, ending a match-arm or let pattern region early, and '"' opened a string in the shared mask.
  • New 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: 'a and 'outer: are left alone. It runs first in parameter_rebound_before only; mask_rust_comments_and_strings and its pinned test are unchanged.
  • Tests: a helper unit test, plus two paired cases in the pattern-position test (Some(n) if c == ';' => and if 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 or let pattern 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_mask unit test passes.
  • cargo xtask precommit exit 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU

…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
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 171 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 4b7f2dd8-5722-4aff-9791-e36d22e0e2d2
Commits

Reviewing files that changed from the base of the PR and between 6657a7a and f6f3930.

Files selected for processing: 5
  • changelog.d/10228-char-literal-rebind.md
  • crates/ripr/src/analysis/classify/activation.rs
  • crates/ripr/src/analysis/language/mod.rs
  • crates/ripr/src/analysis/language/rust/mod.rs
  • crates/ripr/src/analysis/language/rust/probes.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Base automatically changed from claude/fix-9774-destructuring-rebind to main October 25, 2026 10:48
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WJr6YizPnC777wfxAd9ubU

Copy link
Copy Markdown
Member Author

Head f6f393001b35213db1b57f1e5017958df8d8192b (main merged in, #10154 now on main).

  • Cow: mask_rust_char_literals borrows when the text has no ', so most bodies allocate nothing (Gemini's suggestion, taken).
  • github-actions questions:
    • Lifetimes: 'a / 'outer: have no closing quote after one character and are left alone. The unit test pins fn f<'a>(x: &'a str) -> &'a str { 'outer: loop { break 'outer; } } unchanged.
    • Escapes: '\0', '\r', '\'', '\\' take the escape branch (backslash plus one byte), and \x41 and \u{..} have their own branches.
    • Multi-byte: width comes from the UTF-8 lead byte, and the unit test checks '\u{e9}' and a literal é, with masked.len() == source.len() asserted for every case.
    • Entry points: the pre-mask runs in parameter_rebound_before, the only caller of pattern_position_binds_before. The shared mask and its pinned test are untouched, so no other call site changes.
  • Proof: classify:: 1709 passed, helper unit test passes, cargo xtask precommit exit 0. The negative experiment (removing the pre-mask) fails the Some(n) if c == ';' => pair.
  • Review: no blocking findings from the bot reviews; the earlier source-review escapes in the same scan were fixed on fix(infection): fail closed on destructuring/pattern rebinding of parameters in local initializers (#9774) #10154. This PR does not touch the Rust missed_credit_ceiling.

Marking Ready with merge-ready.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven marked this pull request as ready for review October 25, 2026 11:39
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Copy link
Copy Markdown
Member Author

Review of record at head f6f393001b35213db1b57f1e5017958df8d8192b.

Merging at this head.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven merged commit 49be767 into main Oct 25, 2026
57 checks passed
@EffortlessSteven
EffortlessSteven deleted the claude/fix-10228-char-literal-mask branch October 25, 2026 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants