]> git.lizzy.rs Git - rust.git/commitdiff
Add test for vecs with overaligned data
authorPeter Atashian <retep998@gmail.com>
Thu, 1 Jun 2017 03:24:19 +0000 (23:24 -0400)
committerPeter Atashian <retep998@gmail.com>
Fri, 2 Jun 2017 10:30:54 +0000 (06:30 -0400)
src/libcollections/tests/lib.rs
src/libcollections/tests/vec.rs

index 6ad5781c5d5fdf1984aee0dc5824bb46164d3d80..66918e0f5f8ae5bbfadb631837388092e8fcc51b 100644 (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)]
index 29f18274962fe04e6c3a517370c401d610f711ca..fdf453b39cf5d9144c21cf9c4091af7c41c44312 100644 (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);
+    }
+}