Skip to content

Commit

Permalink
fix into_iter on ZST
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 31, 2022
1 parent 7f442f8 commit fe29ac9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/alloc/src/vec/into_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() })
Expand Down
6 changes: 6 additions & 0 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit fe29ac9

Please sign in to comment.