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