diff options
| author | bors <bors@rust-lang.org> | 2022-12-25 04:26:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-25 04:26:14 +0000 |
| commit | d9ee0f468f8d07e92da94fe991db91e95822d721 (patch) | |
| tree | debea4b2c8c5487b3f031c226d0118ca3e22db67 | |
| parent | 40d7940bdaf30eab6db0fe67690ac940eb035cc0 (diff) | |
| parent | 6fb314ed7d7b3974cd0d4ba5bc0ca724037cc26a (diff) | |
Auto merge of #106112 - RalfJung:into-iter, r=thomcc
add lib tests for vec::IntoIter alignment issues This adds non-Miri tests for the issue fixed in https://github.com/rust-lang/rust/pull/106084 r? `@thomcc`
| -rw-r--r-- | library/alloc/tests/vec.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/library/alloc/tests/vec.rs b/library/alloc/tests/vec.rs index 7ebed0d5ca6..87adcead8f6 100644 --- a/library/alloc/tests/vec.rs +++ b/library/alloc/tests/vec.rs @@ -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}; @@ -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] |
