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
2 changed files with 3 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
||||||
use crate::array;
|
use crate::array;
|
||||||
use crate::iter::{Fuse, FusedIterator, Iterator, TrustedLen};
|
use crate::iter::{Fuse, FusedIterator, Iterator};
|
||||||
use crate::mem;
|
use crate::mem;
|
||||||
use crate::mem::MaybeUninit;
|
use crate::mem::MaybeUninit;
|
||||||
use crate::ops::{ControlFlow, Try};
|
use crate::ops::{ControlFlow, Try};
|
||||||
|
@ -54,11 +54,7 @@ where
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
let (lower, upper) = self.iter.size_hint();
|
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))
|
(lower / N, upper.map(|n| n / N))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,6 +314,3 @@ where
|
||||||
self.iter.len() / N == 0
|
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)));
|
assert_eq!(it.size_hint(), (0, Some(0)));
|
||||||
|
|
||||||
let it = (1..).array_chunks::<2>();
|
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>();
|
let it = (1..).filter(|x| x % 2 != 0).array_chunks::<2>();
|
||||||
assert_eq!(it.size_hint(), (0, None));
|
assert_eq!(it.size_hint(), (0, None));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue