mirror of https://github.com/rust-lang/rust.git
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`.
This commit is contained in:
parent
b8b14864c0
commit
4db628a801
|
@ -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 {}
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue