Skip to content

feat(ts): translate a reference to a closure as a str pattern - #495

Merged
kixelated merged 4 commits into
mainfrom
quest/m3/ts-closure-patterns
Nov 3, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m3/ts-closure-patterns

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

A str search given a reference to a closure as its pattern, s.contains(&f) or s.split(&mut f), failed translation as an unsupported call. std takes &F for an F: Fn and &mut F for an F: FnMut, as each implements FnMut(char) -> bool.

Approach

pattern in ts/src/lower/library.rs now accepts a closure or a function item behind any references. called_closures, which #471 extended, already reads a lent closure through its place and wraps it in rt.lent for an iterator, and never drops it, so the owner drops it.

ts/fixtures/task/src/drops/searched.rs gains two differential scenarios covering every str search taking a pattern, values and iterators: one by &F owning a guard (plus a cloned iterator and &char::is_whitespace), one by &mut F owning a guard and counting its calls across every search, including through a &mut &mut F. A mutation wrapping a reference pattern in rt.once fails the differential test, so the scenarios catch an early drop.

Impact

  • Translator output: these searches now translate instead of failing. No API change.
  • ts/README.md lists a reference to a predicate among the patterns that translate.

Alternatives

  • Peeling through Box too, via called_through: left out, as an owned Box<F> pattern is its own case with no test here.

Follow-ups

To plan as quests (found while testing, out of scope):

  • A function pointer (fn(char) -> bool) or Box<dyn FnMut(char) -> bool> as a str pattern: pattern matches no ty::FnPtr or Box.
  • char::is_alphabetic (and other char methods without a mapping) as a function value: "unsupported call".

Review

  • Codex, gpt-6.1-sol, medium, round 1, head 98138d58: no findings.
  • Head 0360e228 adds only conflict-free merges of origin/main; just ci passed on it.

🤖 Generated with Claude Code

kixelated and others added 3 commits November 2, 2026 22:36
`s.contains(&f)` and `s.split(&mut f)` now translate for every `str` search,
calling the borrowed closure as std does and leaving its drop to its owner.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A reference to a closure as a string pattern feat(ts): translate a reference to a closure as a str pattern Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 06:53
@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 54 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: cface447-1e7c-4343-b389-1b22ac4cc9ea
Commits

Reviewing files that changed from the base of the PR and between 7c41f2b and 0360e22.

Files selected for processing: 7
  • quest/m3/README.md
  • quest/m3/ts-closure-patterns.md
  • ts/README.md
  • ts/fixtures/task/expected/drops/searched.ts
  • ts/fixtures/task/src/drops/searched.rs
  • ts/src/lower/library.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
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 5294768 Nov 3, 2026
5 checks passed
@kixelated
kixelated deleted the quest/m3/ts-closure-patterns branch November 3, 2026 07:09
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