Skip to content

Commit 4660cc6

Browse files
Rollup merge of rust-lang#123406 - krtab:fix_remainder_iterchunk, r=scottmcm
Force exhaustion in iter::ArrayChunks::into_remainder Closes: rust-lang#123333
2 parents c628501 + f46c501 commit 4660cc6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

core/src/iter/adapters/array_chunks.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,22 @@ where
3434
/// Returns an iterator over the remaining elements of the original iterator
3535
/// that are not going to be returned by this iterator. The returned
3636
/// iterator will yield at most `N-1` elements.
37+
///
38+
/// # Example
39+
/// ```
40+
/// # // Also serves as a regression test for https://github.com/rust-lang/rust/issues/123333
41+
/// # #![feature(iter_array_chunks)]
42+
/// let x = [1,2,3,4,5].into_iter().array_chunks::<2>();
43+
/// let mut rem = x.into_remainder().unwrap();
44+
/// assert_eq!(rem.next(), Some(5));
45+
/// assert_eq!(rem.next(), None);
46+
/// ```
3747
#[unstable(feature = "iter_array_chunks", reason = "recently added", issue = "100450")]
3848
#[inline]
39-
pub fn into_remainder(self) -> Option<array::IntoIter<I::Item, N>> {
49+
pub fn into_remainder(mut self) -> Option<array::IntoIter<I::Item, N>> {
50+
if self.remainder.is_none() {
51+
while let Some(_) = self.next() {}
52+
}
4053
self.remainder
4154
}
4255
}

0 commit comments

Comments
 (0)