diff options
| author | Jubilee <46493976+workingjubilee@users.noreply.github.com> | 2024-04-18 21:38:54 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-18 21:38:54 -0700 |
| commit | 3831cbb28f468f271ecffebac960ac4ea644e53a (patch) | |
| tree | 47f8cf7160f2c90e4492b165644530c5ee186142 | |
| parent | fa0068b5412baecc932772dda72c0621bfa7ab00 (diff) | |
| parent | d9a89038865117234dac72f287863a78ce81d1c9 (diff) | |
| download | rust-3831cbb28f468f271ecffebac960ac4ea644e53a.tar.gz rust-3831cbb28f468f271ecffebac960ac4ea644e53a.zip | |
Rollup merge of #123406 - krtab:fix_remainder_iterchunk, r=scottmcm
Force exhaustion in iter::ArrayChunks::into_remainder Closes: #123333
| -rw-r--r-- | library/core/src/iter/adapters/array_chunks.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/library/core/src/iter/adapters/array_chunks.rs b/library/core/src/iter/adapters/array_chunks.rs index 8c68ea114db..8f1744fc5fb 100644 --- a/library/core/src/iter/adapters/array_chunks.rs +++ b/library/core/src/iter/adapters/array_chunks.rs @@ -34,9 +34,22 @@ where /// Returns an iterator over the remaining elements of the original iterator /// that are not going to be returned by this iterator. The returned /// iterator will yield at most `N-1` elements. + /// + /// # Example + /// ``` + /// # // Also serves as a regression test for https://github.com/rust-lang/rust/issues/123333 + /// # #![feature(iter_array_chunks)] + /// let x = [1,2,3,4,5].into_iter().array_chunks::<2>(); + /// let mut rem = x.into_remainder().unwrap(); + /// assert_eq!(rem.next(), Some(5)); + /// assert_eq!(rem.next(), None); + /// ``` #[unstable(feature = "iter_array_chunks", reason = "recently added", issue = "100450")] #[inline] - pub fn into_remainder(self) -> Option<array::IntoIter<I::Item, N>> { + pub fn into_remainder(mut self) -> Option<array::IntoIter<I::Item, N>> { + if self.remainder.is_none() { + while let Some(_) = self.next() {} + } self.remainder } } |
