Repository navigation
feat(ts): read a boxed iterator as std's Iterator for Box<I> does - #490
Merged
Merged
Conversation
Quest-Claim: c993241894bc93d0
A box of an iterator, a trait object or not, owned or behind a `&mut`, is rt.iterBox of it: it forwards next, size_hint, nth, last, and the double-ended and exact-size methods, and reads the rest by next, advance_by and the folds included, where the translation folded what the box held by its own folds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…does 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 06:13
|
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 4 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
|
kixelated
added a commit
that referenced
this pull request
Nov 3, 2026
Keeps one box reader, main's rt.iterBox from #490, and deletes this branch's rt.iterBoxed with its own wrapping in into_iter. iterBox already forwards only what std's Box<I> does, so a box of the crate's own iterator, or of an adaptor holding one, never reaches its by-value overrides. ends' boxed Overrides cases and zips' boxed reads stay beside #490's dyns cases. 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 erased a
Box<I>and folded what it held with that iterator's own folds. std'sIteratorforBox<I>forwards onlynext,size_hint,nth,last,next_back,nth_back, andlen/is_empty, and reads everything else bynext,advance_byand the folds included. SoBox::new(a.map(f).zip(b.map(g)).skip(1)).count()made the skipped pair whole, where native skips it one side at a time through the zip'snth. It also read a zip's excess left item in a different order.The same gap affected
Box<dyn Iterator>, which went throughrt.iterDynand so forwardedadvance_by. That is right for&mut dyn Iteratorbut not for a box, which readsadvance_bybynext(for example throughChain::nth).Approach
rt.iterBox(it): a runtime wrapper that forwards exactly what std's box forwards. Itslastdispatches to the held iterator's ownlast, in bothownedLastand the non-droppingiterLast. Everything else falls back to theIterdefaults, which read bynext.DynandBoxednow share aForwardbase, andDynaddsadvanceBy/advanceBackBy.into_iterwraps by the box layers of the type it was given (boxes):rt.iterBox;rt.iterBorrow(rt.iterBox(..)), so&mut Box<I>folds and takeslastbynext, as std's&mut Iover a box does.callnow passes the originalself_tyand receiver tointo_iter, so a consumer sees the box.Proof:
lang/dynsgainsdyns::boxes. It runs a skip of a TRA zip whose items log as they are made and dropped, through every consumer: forwarded (size_hint,len,next,next_back,nth,nth_back,last,Box<Box<I>>::last) and by-next(count,fold,for_each,position,find,any,max_by_key,collect,rev().fold,sum,skip,step_by,Chain::nth'sadvance_by). Each is checked owned, behind&mut, as aBox<&mut I>, and asBox<dyn>vs&mut dyn. A non-dropping logging zip coverslastin theiterLastpath. Mutation checks pass: forwardingadvanceByinBoxed, dropping thelastdispatch, or dropping the borrowed-box wrap each fails the differential test.Impact
rt.iterBox(..)where it is read. Snapshot churn inlang/dynsandlang/iters.rt.iterBox. Nothing removed.Alternatives
peel_iter, which is exact per layer. Collapsing them inboxesgives the same semantics with less code, sinceiterBorrow(iterBox(x))reads alike whateverxholds.Box<dyn>coercion. That missesBox<I>of sized iterators, and&mut *boxed_dynwould wrongly loseadvance_byforwarding.Follow-ups
rt.iterFromexceptlast. Once this lands,rt.iterBoxalready reads that box bynextand forwards onlylast, so itsboxedflag inown_methodsbecomes redundant and can be dropped when Folds from the back, and a crate's own folds #463 merges main. Thecallhunk here matches Folds from the back, and a crate's own folds #463's line for line, to keep that merge trivial.Review
Codex gpt-6.1-sol, medium, via
quest review.iterLastread a box bynextinstead of forwardinglast. Fixed in f1f5ee6, with a fixture case that fails without the fix.🤖 Generated with Claude Code