Skip to content

Commit 2a02882

Browse files
authored
Rollup merge of #101237 - RalfJung:into-iter-zst, r=thomcc
fix into_iter on ZST Fixes #101235 Thanks to `@ChrisDenton` for [spotting the problem](#100819 (review)).
2 parents cc02024 + fe29ac9 commit 2a02882

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

library/alloc/src/vec/into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
266266
None
267267
} else if mem::size_of::<T>() == 0 {
268268
// See above for why 'ptr.offset' isn't used
269-
self.end = self.ptr.wrapping_byte_sub(1);
269+
self.end = self.end.wrapping_byte_sub(1);
270270

271271
// Make up a value of this ZST.
272272
Some(unsafe { mem::zeroed() })

library/alloc/tests/vec.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,12 @@ fn test_into_iter_drop_allocator() {
11041104
assert_eq!(drop_count, 2);
11051105
}
11061106

1107+
#[test]
1108+
fn test_into_iter_zst() {
1109+
for _ in vec![[0u64; 0]].into_iter() {}
1110+
for _ in vec![[0u64; 0]; 5].into_iter().rev() {}
1111+
}
1112+
11071113
#[test]
11081114
fn test_from_iter_specialization() {
11091115
let src: Vec<usize> = vec![0usize; 1];

0 commit comments

Comments
 (0)