Skip to content

Commit

Permalink
Rollup merge of #101237 - RalfJung:into-iter-zst, r=thomcc
Browse files Browse the repository at this point in the history
fix into_iter on ZST

Fixes rust-lang/rust#101235
Thanks to `@ChrisDenton` for [spotting the problem](rust-lang/rust#100819 (review)).
  • Loading branch information
RalfJung authored Aug 31, 2022
2 parents dd0dac5 + facd4c0 commit d4b4ff0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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 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 d4b4ff0

Please sign in to comment.