Skip to content

Commit a48d2e1

Browse files
committed
fix one more unaligned self.ptr, and add tests
1 parent d0f404d commit a48d2e1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

library/alloc/src/vec/into_iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
251251
return Err(unsafe { array::IntoIter::new_unchecked(raw_ary, 0..len) });
252252
}
253253

254-
self.ptr = self.ptr.wrapping_byte_add(N);
254+
self.end = self.end.wrapping_byte_sub(N);
255255
// Safety: ditto
256256
return Ok(unsafe { raw_ary.transpose().assume_init() });
257257
}

src/tools/miri/tests/pass/vec.rs

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@compile-flags: -Zmiri-strict-provenance
2+
#![feature(iter_advance_by, iter_next_chunk)]
3+
24
// Gather all references from a mutable iterator and make sure Miri notices if
35
// using them is dangerous.
46
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
@@ -44,6 +46,18 @@ fn vec_into_iter_zst() {
4446
for _ in vec![[0u64; 0]].into_iter() {}
4547
let v = vec![[0u64; 0], [0u64; 0]].into_iter().map(|x| x.len()).sum::<usize>();
4648
assert_eq!(v, 0);
49+
50+
let mut it = vec![[0u64; 0], [0u64; 0]].into_iter();
51+
it.advance_by(1);
52+
drop(it);
53+
54+
let mut it = vec![[0u64; 0], [0u64; 0]].into_iter();
55+
it.next_chunk::<1>().unwrap();
56+
drop(it);
57+
58+
let mut it = vec![[0u64; 0], [0u64; 0]].into_iter();
59+
it.next_chunk::<4>().unwrap_err();
60+
drop(it);
4761
}
4862

4963
fn vec_into_iter_rev_zst() {

0 commit comments

Comments
 (0)