Repository navigation
fix(ts): translate the crate's own iterator held as a value, taken by value or by std's &mut self methods - #540
Merged
Merged
Conversation
Quest-Claim: d917dcdfbd57ca06
…ace of its own 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 19:25
|
This run was cancelled before it finished. |
|
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 24 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
|
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
A crate's own iterator whose JS value is copied, as an enum's is, failed to type-check when taken by value:
toggle.map(f)gavert.iterFromthe enum's value where itsnexttakes anrt.Place(found by #515). The same held for every by-value use (filter,zip,chain,collect,extend,sum,rev,cycle,IntoIteratorof a crate type returning one), and for std's methods taking&mut self(nth,any,find,position), whose mapping got the enum's value, so writes landed in a copy and a value that drops dropped twice. A borrowed one ((&mut toggle).map(f)) also passed the place to its own&selfoverrides (size_hint,len), which take the value.Approach
into_iterof an owned one moves it into a place of its own,{ v: value }; its dropper and its overrides that takeselfor&selfreadit.v, and its clone (forcycleandclone) makes a new place.IteratorandDoubleEndedIteratormethods of such an iterator take the&mut's place (pointer::takes_place), and a std method taking&mut selfof the crate's own iterator borrows it, sointo_itergives no dropper and only the overrides std's&mut Iforwards. For a struct, this drops the by-valuefold,count, andlastfrom whattry_fold,rposition, and the like may call (theendsandstocksnapshot changes); std's never call them there.iters::by_valuedifferential case: a fieldless enum with its ownsize_hint,count, andnext_back, an enum holding a value that logs as it drops, and a struct that logs as it drops, through adaptors, consumers,for,extend,cycle,IntoIteratorof a crate type, adaptors dropped partway, and std's&mut selfmethods on a local.quest/m3/ts-std-stragglers.md.Impact
&mut selfmethods. No public API change.Alternatives
rt.iterFromvariant that knows whichOwnmethods take&mut self: duplicates the trait's signatures in the runtime, where the translator reads them from rustc.Follow-ups
Consumer: none yet, planned as part of std (m3).
Review
Codex (
quest review), gpt-6.1-sol, medium effort, round 1 on head 5d8d8a5 against origin/main f0b2a31: no findings. Head 3c0fc4b adds only a conflict-free merge of origin/main.🤖 Generated with Claude Code