Skip to content

Commit 4db628a

Browse files
committed
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`.
1 parent b8b1486 commit 4db628a

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

library/core/src/iter/adapters/array_chunks.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::array;
2-
use crate::iter::{Fuse, FusedIterator, Iterator, TrustedLen};
2+
use crate::iter::{Fuse, FusedIterator, Iterator};
33
use crate::mem;
44
use crate::mem::MaybeUninit;
55
use crate::ops::{ControlFlow, Try};
@@ -54,11 +54,7 @@ where
5454
#[inline]
5555
fn size_hint(&self) -> (usize, Option<usize>) {
5656
let (lower, upper) = self.iter.size_hint();
57-
// Keep infinite iterator size hint lower bound as `usize::MAX`. This
58-
// is required to implement `TrustedLen`.
59-
if lower == usize::MAX {
60-
return (lower, upper);
61-
}
57+
6258
(lower / N, upper.map(|n| n / N))
6359
}
6460

@@ -318,6 +314,3 @@ where
318314
self.iter.len() / N == 0
319315
}
320316
}
321-
322-
#[unstable(feature = "trusted_len", issue = "37572")]
323-
unsafe impl<I, const N: usize> TrustedLen for ArrayChunks<I, N> where I: TrustedLen {}

library/core/tests/iter/adapters/array_chunks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn test_iterator_array_chunks_size_hint() {
5050
assert_eq!(it.size_hint(), (0, Some(0)));
5151

5252
let it = (1..).array_chunks::<2>();
53-
assert_eq!(it.size_hint(), (usize::MAX, None));
53+
assert_eq!(it.size_hint(), (usize::MAX / 2, None));
5454

5555
let it = (1..).filter(|x| x % 2 != 0).array_chunks::<2>();
5656
assert_eq!(it.size_hint(), (0, None));

0 commit comments

Comments
 (0)