2016-06-13 07:27:05 -05:00
|
|
|
#![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
|
|
|
|
2016-06-13 04:24:01 -05:00
|
|
|
fn allocate_reallocate() {
|
|
|
|
let mut s = String::new();
|
|
|
|
|
2016-09-13 21:13:30 -05:00
|
|
|
// 4 byte heap alloc (__rust_allocate)
|
|
|
|
s.push('f');
|
|
|
|
assert_eq!(s.len(), 1);
|
|
|
|
assert_eq!(s.capacity(), 4);
|
2016-06-13 04:24:01 -05:00
|
|
|
|
2016-09-13 21:13:30 -05:00
|
|
|
// heap size doubled to 8 (__rust_reallocate)
|
|
|
|
// FIXME: String::push_str is broken because it hits the std::vec::SetLenOnDrop code and we
|
|
|
|
// don't call destructors in miri yet.
|
|
|
|
s.push('o');
|
|
|
|
s.push('o');
|
|
|
|
s.push('o');
|
|
|
|
s.push('o');
|
|
|
|
assert_eq!(s.len(), 5);
|
|
|
|
assert_eq!(s.capacity(), 8);
|
2016-06-13 04:24:01 -05:00
|
|
|
|
2016-09-13 21:13:30 -05:00
|
|
|
// heap size reduced to 5 (__rust_reallocate)
|
2016-06-13 04:24:01 -05:00
|
|
|
s.shrink_to_fit();
|
2016-09-13 21:13:30 -05:00
|
|
|
assert_eq!(s.len(), 5);
|
|
|
|
assert_eq!(s.capacity(), 5);
|
2016-06-13 04:24:01 -05:00
|
|
|
}
|
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(*make_box(), (1, 2));
|
|
|
|
assert_eq!(*make_box_syntax(), (1, 2));
|
2016-06-13 07:27:05 -05:00
|
|
|
allocate_reallocate();
|
2016-04-22 07:38:46 -05:00
|
|
|
}
|