Skip to content

fix(ts): drop a string search's or retain's closure where std does - #471

Merged
kixelated merged 6 commits into
mainfrom
quest/m3/ts-string-closures
Nov 3, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/m3/ts-string-closures

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts refused a closure that owns a value that drops when it was given to String::retain or as a str search's Pattern (contains, split, and the rest), as the reject fixture's string_retained and pattern_closure showed. Completes quest/m3/ts-string-closures.md.

Approach

  • called_by reads a Pattern bound as calling its closure by FnMut, so called_closures decides its drop as it does for any other closure std calls: rt.dropAfter for a search that returns a value, and the returned iterator for one that returns an iterator.
  • holds_closure lists str's search iterators. drops counts one as dropping when its closure does, because std nests the closure inside internal searcher structs that no rt.Iter stands for.
  • Runtime: str.ts's Searcher drops its pattern once, and Split, Matches, and MatchIndices drop their searcher. rsplit and the other r forms are iterRev of these, which already drops what it wraps.
  • String::retain, lowered in mir/call.rs, drops a closure it owns after assigning the edited string. That is where std's parameter drops, after the length guard.
  • Proof: a new searched step in the task fixture, differential against native Rust:
    • Every value search, matched and unmatched.
    • Every iterator search, read partly, ended by a for with break, collected, counted, last, nth, and wrapped in rev().map().
    • retain with an owned closure, a borrowed &mut one that its owner drops later, and an empty string that never calls its closure.

Impact

  • Translator output: these calls now translate where they were refused. No runtime API is exported or changed.

Alternatives

  • Recursing drops into all of std's internal structs, which would also reach the searcher. Rejected: it changes how every std type drops. The holds_closure arm reaches only the iterators the runtime drops closures for.

Follow-ups

  • A reference to a closure as a pattern (s.contains(&f), s.split(&mut f)) is still refused as a pattern other than a char, a &str, a predicate, or chars, as the README lists. That gap is separate from drops. It is not a quest yet: suggested for /quest-plan.
  • #463 edits the same reject fixture, census, and task.ts. Whichever lands second regenerates the line-numbered expected.txt and census.md. The code changes don't overlap.

Review

  • Reviewer: Codex, gpt-6.1-sol, medium effort (quest review), round 3.
  • Reviewed head: 7803e3d, which merges origin/main at ccf8d33. The reject fixture's line-numbered expected.txt and census.md conflicted and were regenerated.
  • Findings: none, in this round or in rounds 1 and 2.
  • f586641 and 4c9afea merge origin/main at fdb9bff and 94c22e0, a quest change and an ffi change, without conflicts. just ci passed on each.

🤖 Generated with Claude Code

kixelated and others added 2 commits November 2, 2026 18:17
A closure that owns a value that drops, given to `String::retain` or as a
`str` search's `Pattern`, now drops as the call returns, or with the iterator
a search returns, instead of being refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A closure that drops given to a string's edit or search fix(ts): drop a string search's or retain's closure where std does Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 02:39
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 30 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

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: CHILL
  • Plan: Advanced
  • Run ID: 5efac72a-71c9-49bc-b8e3-07d354e2a11a
Commits

Reviewing files that changed from the base of the PR and between 94c22e0 and 4c9afea.

Files selected for processing: 19
  • quest/m3/README.md
  • quest/m3/ts-string-closures.md
  • ts/README.md
  • ts/fixtures/reject/census.md
  • ts/fixtures/reject/expected.txt
  • ts/fixtures/reject/src/lib.rs
  • ts/fixtures/reject/ts.toml
  • ts/fixtures/task/expected/drops.ts
  • ts/fixtures/task/expected/drops/searched.ts
  • ts/fixtures/task/src/drops.rs
  • ts/fixtures/task/src/drops/searched.rs
  • ts/fixtures/task/src/harness.rs
  • ts/fixtures/task/ts.toml
  • ts/runtime/rt/str.ts
  • ts/src/lower/drop.rs
  • ts/src/lower/iter.rs
  • ts/src/lower/library.rs
  • ts/src/lower/mir/call.rs
  • ts/tests/task.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

kixelated and others added 4 commits November 2, 2026 18:46
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated enabled auto-merge November 3, 2026 03:17
@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 9c33cb2 Nov 3, 2026
5 checks passed
@kixelated
kixelated deleted the quest/m3/ts-string-closures branch November 3, 2026 03:26
kixelated added a commit that referenced this pull request Nov 3, 2026
#471's removed reject cases leave strs.rs, with its roots and expected lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant