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