Skip to content

Commit 42ac311

Browse files
committed
Add test for vecs with overaligned data
1 parent 077c23e commit 42ac311

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/libcollections/tests/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#![deny(warnings)]
1212

13+
#![feature(attr_literals)]
1314
#![feature(box_syntax)]
1415
#![feature(inclusive_range_syntax)]
1516
#![feature(collection_placement)]
@@ -19,6 +20,7 @@
1920
#![feature(pattern)]
2021
#![feature(placement_in_syntax)]
2122
#![feature(rand)]
23+
#![feature(repr_align)]
2224
#![feature(slice_rotate)]
2325
#![feature(splice)]
2426
#![feature(step_by)]

src/libcollections/tests/vec.rs

+15
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,18 @@ fn from_into_inner() {
781781
assert_eq!(vec, [2, 3]);
782782
assert!(ptr != vec.as_ptr());
783783
}
784+
785+
#[test]
786+
fn overaligned_allocations() {
787+
#[repr(align(256))]
788+
struct Foo(usize);
789+
let mut v = vec![Foo(273)];
790+
for i in 0..0x1000 {
791+
v.reserve_exact(i);
792+
assert!(v[0].0 == 273);
793+
assert!(v.as_ptr() as usize & 0xff == 0);
794+
v.shrink_to_fit();
795+
assert!(v[0].0 == 273);
796+
assert!(v.as_ptr() as usize & 0xff == 0);
797+
}
798+
}

0 commit comments

Comments
 (0)