Skip to content

Commit da81a33

Browse files
committed
Box large array to avoid blowing the stack
1 parent afed75a commit da81a33

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/test/run-pass/align-struct.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010
#![feature(attr_literals)]
1111
#![feature(repr_align)]
12+
#![feature(box_syntax)]
1213

1314
use std::mem;
1415

@@ -201,13 +202,14 @@ pub fn main() {
201202
assert_eq!(mem::size_of_val(&a), 16);
202203
assert!(is_aligned_to(&a, 16));
203204

204-
let mut arr = [0; 0x10000];
205-
arr[0] = 132;
206-
let large = AlignLarge {
207-
stuff: arr,
205+
let mut large = box AlignLarge {
206+
stuff: [0; 0x10000],
208207
};
208+
large.stuff[0] = 132;
209+
*large.stuff.last_mut().unwrap() = 102;
209210
assert_eq!(large.stuff[0], 132);
211+
assert_eq!(large.stuff.last(), Some(&102));
210212
assert_eq!(mem::align_of::<AlignLarge>(), 0x10000);
211-
assert_eq!(mem::align_of_val(&large), 0x10000);
212-
assert!(is_aligned_to(&large, 0x10000));
213+
assert_eq!(mem::align_of_val(&*large), 0x10000);
214+
assert!(is_aligned_to(&*large, 0x10000));
213215
}

0 commit comments

Comments
 (0)