Skip to content

Commit e21c46a

Browse files
Adjust TupleWindows::size_hint
Now that `TupleWindows` is lazy, we must adjust the size hint accordingly.
1 parent 22603cc commit e21c46a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/size_hint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub fn add_scalar(sh: SizeHint, x: usize) -> SizeHint {
2929
}
3030

3131
/// Subtract `x` correctly from a `SizeHint`.
32-
#[cfg(feature = "use_alloc")]
3332
#[inline]
3433
pub fn sub_scalar(sh: SizeHint, x: usize) -> SizeHint {
3534
let (mut low, mut hi) = sh;

src/tuple_impl.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::iter::Fuse;
55
use std::iter::FusedIterator;
66
use std::marker::PhantomData;
77

8+
use crate::size_hint;
9+
810
// `HomogeneousTuple` is a public facade for `TupleCollect`, allowing
911
// tuple-related methods to be used by clients in generic contexts, while
1012
// hiding the implementation details of `TupleCollect`.
@@ -209,9 +211,13 @@ where
209211
}
210212

211213
fn size_hint(&self) -> (usize, Option<usize>) {
212-
// At definition, `T::num_items() - 1` are collected
213-
// so each remaining item in `iter` will lead to an item.
214-
self.iter.size_hint()
214+
let mut sh = self.iter.size_hint();
215+
// Adjust the size hint at the beginning
216+
// OR when `num_items == 1` (but it does not change the size hint).
217+
if self.last.is_none() {
218+
sh = size_hint::sub_scalar(sh, T::num_items() - 1);
219+
}
220+
sh
215221
}
216222
}
217223

0 commit comments

Comments
 (0)