Repository navigation
fix(ts): drop a string search's or retain's closure where std does - #471
Merged
Merged
Conversation
Quest-Claim: a243715f93df7da0
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
marked this pull request as ready for review
November 3, 2026 02:39
|
Warning Review limit reachedYou'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. View limit details
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. CodeRabbit Verify
|
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
enabled auto-merge
November 3, 2026 03:17
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>
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
rust2-ts refused a closure that owns a value that drops when it was given to
String::retainor as astrsearch'sPattern(contains,split, and the rest), as the reject fixture'sstring_retainedandpattern_closureshowed. Completes quest/m3/ts-string-closures.md.Approach
called_byreads aPatternbound as calling its closure byFnMut, socalled_closuresdecides its drop as it does for any other closure std calls:rt.dropAfterfor a search that returns a value, and the returned iterator for one that returns an iterator.holds_closurelistsstr's search iterators.dropscounts one as dropping when its closure does, because std nests the closure inside internal searcher structs that nort.Iterstands for.str.ts'sSearcherdrops its pattern once, andSplit,Matches, andMatchIndicesdrop their searcher.rsplitand the otherrforms areiterRevof these, which already drops what it wraps.String::retain, lowered inmir/call.rs, drops a closure it owns after assigning the edited string. That is where std's parameter drops, after the length guard.searchedstep in the task fixture, differential against native Rust:forwithbreak, collected, counted,last,nth, and wrapped inrev().map().retainwith an owned closure, a borrowed&mutone that its owner drops later, and an empty string that never calls its closure.Impact
Alternatives
dropsinto all of std's internal structs, which would also reach the searcher. Rejected: it changes how every std type drops. Theholds_closurearm reaches only the iterators the runtime drops closures for.Follow-ups
s.contains(&f),s.split(&mut f)) is still refused as a pattern other than achar, 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.task.ts. Whichever lands second regenerates the line-numberedexpected.txtandcensus.md. The code changes don't overlap.Review
quest review), round 3.expected.txtandcensus.mdconflicted and were regenerated.just cipassed on each.🤖 Generated with Claude Code