]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/heap.rs
don't use `#[miri_run]` anymore, but execute the `main` function
[rust.git] / tests / run-pass / heap.rs
1 #![feature(box_syntax)]
2
3 fn make_box() -> Box<(i16, i16)> {
4     Box::new((1, 2))
5 }
6
7 fn make_box_syntax() -> Box<(i16, i16)> {
8     box (1, 2)
9 }
10
11 fn allocate_reallocate() {
12     let mut s = String::new();
13
14     // 6 byte heap alloc (__rust_allocate)
15     s.push_str("foobar");
16     assert_eq!(s.len(), 6);
17     assert_eq!(s.capacity(), 6);
18
19     // heap size doubled to 12 (__rust_reallocate)
20     s.push_str("baz");
21     assert_eq!(s.len(), 9);
22     assert_eq!(s.capacity(), 12);
23
24     // heap size reduced to 9  (__rust_reallocate)
25     s.shrink_to_fit();
26     assert_eq!(s.len(), 9);
27     assert_eq!(s.capacity(), 9);
28 }
29
30 fn main() {
31     assert_eq!(*make_box(), (1, 2));
32     assert_eq!(*make_box_syntax(), (1, 2));
33     allocate_reallocate();
34 }