Skip to content

Commit

Permalink
fix one more unaligned self.ptr, and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 23, 2022
1 parent d0f404d commit a48d2e1
Show file tree
Hide file tree
Showing 2 changed files with 15 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 @@ -251,7 +251,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
return Err(unsafe { array::IntoIter::new_unchecked(raw_ary, 0..len) });
}

self.ptr = self.ptr.wrapping_byte_add(N);
self.end = self.end.wrapping_byte_sub(N);
// Safety: ditto
return Ok(unsafe { raw_ary.transpose().assume_init() });
}
Expand Down
14 changes: 14 additions & 0 deletions src/tools/miri/tests/pass/vec.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@compile-flags: -Zmiri-strict-provenance
#![feature(iter_advance_by, iter_next_chunk)]

// Gather all references from a mutable iterator and make sure Miri notices if
// using them is dangerous.
fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>) {
Expand Down Expand Up @@ -44,6 +46,18 @@ fn vec_into_iter_zst() {
for _ in vec![[0u64; 0]].into_iter() {}
let v = vec![[0u64; 0], [0u64; 0]].into_iter().map(|x| x.len()).sum::<usize>();
assert_eq!(v, 0);

let mut it = vec![[0u64; 0], [0u64; 0]].into_iter();
it.advance_by(1);
drop(it);

let mut it = vec![[0u64; 0], [0u64; 0]].into_iter();
it.next_chunk::<1>().unwrap();
drop(it);

let mut it = vec![[0u64; 0], [0u64; 0]].into_iter();
it.next_chunk::<4>().unwrap_err();
drop(it);
}

fn vec_into_iter_rev_zst() {
Expand Down

0 comments on commit a48d2e1

Please sign in to comment.