fix into_iter on ZST

This commit is contained in:
Ralf Jung 2022-08-31 14:21:35 +02:00
parent 7f442f8ba1
commit fe29ac9a44
2 changed files with 7 additions and 1 deletions

View file

@ -266,7 +266,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
None
} else if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used
self.end = self.ptr.wrapping_byte_sub(1);
self.end = self.end.wrapping_byte_sub(1);
// Make up a value of this ZST.
Some(unsafe { mem::zeroed() })

View file

@ -1104,6 +1104,12 @@ fn test_into_iter_drop_allocator() {
assert_eq!(drop_count, 2);
}
#[test]
fn test_into_iter_zst() {
for _ in vec![[0u64; 0]].into_iter() {}
for _ in vec![[0u64; 0]; 5].into_iter().rev() {}
}
#[test]
fn test_from_iter_specialization() {
let src: Vec<usize> = vec![0usize; 1];