From 67c47ba3254ba83ce77787b321f2a979ea7262a9 Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Sat, 16 May 2026 20:06:07 -0400 Subject: [PATCH] take_while_inclusive: tighten FusedIterator to require I: FusedIterator The current impl marks TakeWhileInclusive as FusedIterator regardless of the underlying iterator, so wrapping a non-fused iterator and then calling .fuse() is unsound: TakeWhileInclusive forwards next() to the inner iterator after it returns None once, and the .fuse() layer takes the FusedIterator marker at face value and short-circuits to None. Calling next() a second time can then yield Some after the first None, breaking the FusedIterator contract. Mirror std::iter::TakeWhile and only implement FusedIterator when the inner iterator is fused. Closes #1088 Signed-off-by: Charlie Tonneslan --- src/take_while_inclusive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/take_while_inclusive.rs b/src/take_while_inclusive.rs index 420da9847..660a0e0d3 100644 --- a/src/take_while_inclusive.rs +++ b/src/take_while_inclusive.rs @@ -90,7 +90,7 @@ where impl FusedIterator for TakeWhileInclusive where - I: Iterator, + I: FusedIterator, F: FnMut(&I::Item) -> bool, { }