Add test for vecs with overaligned data

This commit is contained in:
Peter Atashian 2017-05-31 23:24:19 -04:00
parent 077c23e987
commit 42ac31182b
No known key found for this signature in database
GPG Key ID: DE04D9E27559BC8A
2 changed files with 17 additions and 0 deletions

View File

@ -10,6 +10,7 @@
#![deny(warnings)]
#![feature(attr_literals)]
#![feature(box_syntax)]
#![feature(inclusive_range_syntax)]
#![feature(collection_placement)]
@ -19,6 +20,7 @@
#![feature(pattern)]
#![feature(placement_in_syntax)]
#![feature(rand)]
#![feature(repr_align)]
#![feature(slice_rotate)]
#![feature(splice)]
#![feature(step_by)]

View File

@ -781,3 +781,18 @@ fn from_into_inner() {
assert_eq!(vec, [2, 3]);
assert!(ptr != vec.as_ptr());
}
#[test]
fn overaligned_allocations() {
#[repr(align(256))]
struct Foo(usize);
let mut v = vec![Foo(273)];
for i in 0..0x1000 {
v.reserve_exact(i);
assert!(v[0].0 == 273);
assert!(v.as_ptr() as usize & 0xff == 0);
v.shrink_to_fit();
assert!(v[0].0 == 273);
assert!(v.as_ptr() as usize & 0xff == 0);
}
}