Only implement FusedIterator for TakeWhileInclusive when the inner iterator is fused#1110
Merged
phimuemue merged 1 commit intoJun 25, 2026
Conversation
…erator is fused TakeWhileInclusive sets its `done` flag only when the predicate rejects an element, not when the inner iterator returns None. With a non-fused inner iterator it can therefore yield Some after returning None, which breaks the FusedIterator contract it currently claims for every Iterator. Bound the impl on `I: FusedIterator`, matching std::iter::TakeWhile. Fixes rust-itertools#1088
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1110 +/- ##
==========================================
- Coverage 94.38% 93.93% -0.46%
==========================================
Files 48 52 +4
Lines 6665 6679 +14
==========================================
- Hits 6291 6274 -17
- Misses 374 405 +31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
via the queue into
rust-itertools:master
with commit Jun 25, 2026
75ac95b
13 of 14 checks passed
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.
Fixes #1088.
TakeWhileInclusivesets itsdoneflag only when the predicate rejects an element. It does not set it when the inner iterator returnsNone, so with a non-fused inner iterator the adaptor can returnSomeagain after aNone. TheFusedIteratorimpl is currently unconditional (where I: Iterator), so that contract is violated.This bounds the impl on
I: FusedIterator, which is the same approachstd::iter::TakeWhiletakes (option 3 in the issue) and matches how the other conditionally-fused adaptors here are written (for exampleInterleaveShortest).Note this is technically breaking:
TakeWhileInclusiveno longer implementsFusedIteratorwhen the inner iterator isn't fused. The previous impl was unsound in that case, so I left the changelog placement for release prep.Added a
fused_take_while_inclusivequickcheck test mirroringfused_interleave_shortest: not fused over the deliberately non-fusedIter, fused once the inner iterator is.fuse()d.cargo test,cargo fmt --check, andcargo clippy --all-features --all-targetsall pass.