Skip to content

Commit 75ac95b

Browse files
Patrick Wehbephimuemue
authored andcommitted
Only implement FusedIterator for TakeWhileInclusive when the inner iterator 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 #1088
1 parent 37bd72a commit 75ac95b

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/take_while_inclusive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ where
9090

9191
impl<I, F> FusedIterator for TakeWhileInclusive<I, F>
9292
where
93-
I: Iterator,
93+
I: FusedIterator,
9494
F: FnMut(&I::Item) -> bool,
9595
{
9696
}

tests/quick.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,12 @@ quickcheck! {
19861986
is_fused(a.fuse().interleave_shortest(b.fuse()))
19871987
}
19881988

1989+
fn fused_take_while_inclusive(a: Iter<i16>) -> bool
1990+
{
1991+
!is_fused(a.clone().take_while_inclusive(|_| true)) &&
1992+
is_fused(a.fuse().take_while_inclusive(|_| true))
1993+
}
1994+
19891995
fn fused_product(a: Iter<i16>, b: Iter<i16>) -> bool
19901996
{
19911997
is_fused(a.fuse().cartesian_product(b.fuse()))

0 commit comments

Comments
 (0)