fix one more unaligned self.ptr, and add tests

This commit is contained in:
Ralf Jung 2022-12-23 15:49:23 +01:00
parent d0f404d77a
commit a48d2e1783
2 changed files with 15 additions and 1 deletions

View file

@ -251,7 +251,7 @@ fn count(self) -> usize {
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() });
}

View file

@ -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>) {
@ -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() {