Repository navigation
feat(ts): translate std's function values as their calls, mem::take included - #470
Merged
Merged
Conversation
Quest-Claim: 7910f226767c4944
std's take, replace, swap, and the other calls that write what a `&mut` borrows lower only from MIR, so passed as a value they were refused. Their value is now an arrow of rustc's reify shim, lowered as any body. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A reify shim of std's `next` took the item-or-`rt.DONE` protocol of `next`'s own body, and the crate's own `next` as a value was its symbol, which returns the same; both now return the `Option`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 04:05
|
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 18 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>
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 std functions that write what a
&mutborrows when passed as a value, such asv.iter_mut().map(std::mem::take): "unsupported call tostd::mem::take::<Vec<u8>>".mem::take,replace,swap,Option::replace,String::push/push_str,Clone::clone_from,u8::make_ascii_uppercase, and the rest ofintercept's calls lower only from a MIR call, which has the place. A function value instead got a hand-written arrow over the library mappings, which lack them. The same gap hitf(place, value)inside a generic instantiated with such a function.Approach
_0 = f(move _1, ...)), lowered withFxas any body. Its call goes through the same path as a written call,interceptand the&mutpointee handling included. The shim's spans are moved to the use site, and its arguments are nameda0on, as before.FnOnce::call_onceof a mapped stdFnDefthat takes a&mutcalls that value. Other std calls keep the inlinecall_def, soOption::map(x, From::from)staysx.Body::fn_value. Constructors keep their arrow.nextkeeps its call'sOption: a shim of std'snextno longer takes the item-or-rt.DONEprotocol ofnext's own body, and the crate's ownnextas a value goes through the shim too instead of being its bare symbol. That bare symbol leakedrt.DONEbefore this PR.edits::values: take/replace/swap as values throughmap, a generic helper, andfnpointers, on bytes (places), objects written in place (Vec), andStrings. It also checks drop order of replaced values against native Rust, plus the other place-writing std calls above as values, and std's and the crate's ownnextasfnpointers called past the end.Impact
$hashsuffixes in snapshots are renumbered where std instances' text changed. No public Rust API change.Alternatives
interceptand drift from it.call_once: rejected, because it turns identity conversions in translated std generics into IIFEs.Follow-ups
<u8 as AddAssign>::add_assignand the otherstd::opsmethods called by path, written or as a value.Review
gpt-6.1-sol, medium effort, viaquest review. Latest round 4 on heada4a2935b: no findings.nextreturnedrt.DONE: fixed in422dc352, along with the same leak for the crate's ownnextas a value. Both are covered by the differential.main, including moq-dev/rust2#474's fixture split.edits::valuesnow lives ints/fixtures/lang/edits, and the only conflicts were the case registration and regenerated snapshots.🤖 Generated with Claude Code