rust/tests/run-pass-fullmir/heap.rs

36 lines
745 B
Rust
Raw Normal View History

2017-09-16 06:32:38 -05:00
//ignore-msvc
#![feature(box_syntax)]
2016-03-14 23:05:50 -05:00
2016-03-15 00:25:13 -05:00
fn make_box() -> Box<(i16, i16)> {
Box::new((1, 2))
}
fn make_box_syntax() -> Box<(i16, i16)> {
box (1, 2)
2016-03-14 23:05:50 -05:00
}
2016-04-22 03:34:14 -05:00
fn allocate_reallocate() {
let mut s = String::new();
// 6 byte heap alloc (__rust_allocate)
s.push_str("foobar");
assert_eq!(s.len(), 6);
assert_eq!(s.capacity(), 6);
// heap size doubled to 12 (__rust_reallocate)
s.push_str("baz");
assert_eq!(s.len(), 9);
assert_eq!(s.capacity(), 12);
// heap size reduced to 9 (__rust_reallocate)
s.shrink_to_fit();
assert_eq!(s.len(), 9);
assert_eq!(s.capacity(), 9);
}
2016-04-22 07:38:46 -05:00
fn main() {
assert_eq!(*make_box(), (1, 2));
assert_eq!(*make_box_syntax(), (1, 2));
allocate_reallocate();
2016-04-22 07:38:46 -05:00
}