diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-08-01 18:30:55 +0400 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-08-01 19:16:24 +0400 |
| commit | 4db628a801d9efae4fe36d54b9e7deee61f341fb (patch) | |
| tree | 48df84149a49b51d19c0754a5c91a8b4ad68b396 | |
| parent | b8b14864c08cb3d2830006377cbb7ac8741bbb91 (diff) | |
| download | rust-4db628a801d9efae4fe36d54b9e7deee61f341fb.tar.gz rust-4db628a801d9efae4fe36d54b9e7deee61f341fb.zip | |
Remove incorrect impl `TrustedLen` for `ArrayChunks`
As explained in the review of the previous attempt to add `ArrayChunks`, adapters that shrink the length can't implement `TrustedLen`.
| -rw-r--r-- | library/core/src/iter/adapters/array_chunks.rs | 11 | ||||
| -rw-r--r-- | library/core/tests/iter/adapters/array_chunks.rs | 2 |
2 files changed, 3 insertions, 10 deletions
diff --git a/library/core/src/iter/adapters/array_chunks.rs b/library/core/src/iter/adapters/array_chunks.rs index e25a6f9754b..c2de5efed1a 100644 --- a/library/core/src/iter/adapters/array_chunks.rs +++ b/library/core/src/iter/adapters/array_chunks.rs @@ -1,5 +1,5 @@ use crate::array; -use crate::iter::{Fuse, FusedIterator, Iterator, TrustedLen}; +use crate::iter::{Fuse, FusedIterator, Iterator}; use crate::mem; use crate::mem::MaybeUninit; use crate::ops::{ControlFlow, Try}; @@ -54,11 +54,7 @@ where #[inline] fn size_hint(&self) -> (usize, Option<usize>) { let (lower, upper) = self.iter.size_hint(); - // Keep infinite iterator size hint lower bound as `usize::MAX`. This - // is required to implement `TrustedLen`. - if lower == usize::MAX { - return (lower, upper); - } + (lower / N, upper.map(|n| n / N)) } @@ -318,6 +314,3 @@ where self.iter.len() / N == 0 } } - -#[unstable(feature = "trusted_len", issue = "37572")] -unsafe impl<I, const N: usize> TrustedLen for ArrayChunks<I, N> where I: TrustedLen {} diff --git a/library/core/tests/iter/adapters/array_chunks.rs b/library/core/tests/iter/adapters/array_chunks.rs index dbcfd456028..4e9d89e1e58 100644 --- a/library/core/tests/iter/adapters/array_chunks.rs +++ b/library/core/tests/iter/adapters/array_chunks.rs @@ -50,7 +50,7 @@ fn test_iterator_array_chunks_size_hint() { assert_eq!(it.size_hint(), (0, Some(0))); let it = (1..).array_chunks::<2>(); - assert_eq!(it.size_hint(), (usize::MAX, None)); + assert_eq!(it.size_hint(), (usize::MAX / 2, None)); let it = (1..).filter(|x| x % 2 != 0).array_chunks::<2>(); assert_eq!(it.size_hint(), (0, None)); |
