Skip to content

Commit

Permalink
Auto merge of #106112 - RalfJung:into-iter, r=thomcc
Browse files Browse the repository at this point in the history
add lib tests for vec::IntoIter alignment issues

This adds non-Miri tests for the issue fixed in rust-lang/rust#106084

r? `@thomcc`
  • Loading branch information
bors committed Dec 25, 2022
2 parents 339f9cd + 4170f3b commit 88b6c87
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::borrow::Cow;
use std::cell::Cell;
use std::collections::TryReserveErrorKind::*;
use std::fmt::Debug;
use std::hint;
use std::iter::InPlaceIterable;
use std::mem;
use std::mem::{size_of, swap};
use std::ops::Bound::*;
use std::panic::{catch_unwind, AssertUnwindSafe};
Expand Down Expand Up @@ -1107,8 +1109,31 @@ fn test_into_iter_drop_allocator() {

#[test]
fn test_into_iter_zst() {
for _ in vec![[0u64; 0]].into_iter() {}
for _ in vec![[0u64; 0]; 5].into_iter().rev() {}
#[derive(Debug, Clone)]
struct AlignedZstWithDrop([u64; 0]);
impl Drop for AlignedZstWithDrop {
fn drop(&mut self) {
let addr = self as *mut _ as usize;
assert!(hint::black_box(addr) % mem::align_of::<u64>() == 0);
}
}

const C: AlignedZstWithDrop = AlignedZstWithDrop([0u64; 0]);

for _ in vec![C].into_iter() {}
for _ in vec![C; 5].into_iter().rev() {}

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

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

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

#[test]
Expand Down

0 comments on commit 88b6c87

Please sign in to comment.