2016-09-13 21:13:30 -05:00
|
|
|
// FIXME: The normal `vec!` macro is currently broken in Miri because it hits the
|
|
|
|
// std::vec::SetLenOnDrop code and Miri doesn't call destructors yet.
|
|
|
|
macro_rules! miri_vec {
|
|
|
|
($($e:expr),*) => ({
|
|
|
|
let mut v = Vec::new();
|
|
|
|
$(v.push($e);)*
|
|
|
|
v
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:29:56 -05:00
|
|
|
fn make_vec() -> Vec<u8> {
|
2016-03-21 03:41:07 -05:00
|
|
|
let mut v = Vec::with_capacity(4);
|
2016-03-20 21:18:09 -05:00
|
|
|
v.push(1);
|
|
|
|
v.push(2);
|
|
|
|
v
|
|
|
|
}
|
|
|
|
|
2016-04-06 18:29:56 -05:00
|
|
|
fn make_vec_macro() -> Vec<u8> {
|
2016-09-13 21:13:30 -05:00
|
|
|
miri_vec![1, 2]
|
2016-03-21 03:41:22 -05:00
|
|
|
}
|
2016-03-21 04:19:07 -05:00
|
|
|
|
2016-03-21 04:42:34 -05:00
|
|
|
fn make_vec_macro_repeat() -> Vec<u8> {
|
2016-09-13 21:13:30 -05:00
|
|
|
miri_vec![42, 42, 42, 42, 42]
|
2016-03-21 04:42:34 -05:00
|
|
|
}
|
|
|
|
|
2016-04-13 07:12:28 -05:00
|
|
|
fn vec_into_iter() -> u8 {
|
2016-09-13 21:13:30 -05:00
|
|
|
miri_vec![1, 2, 3, 4]
|
2016-04-13 07:12:28 -05:00
|
|
|
.into_iter()
|
|
|
|
.map(|x| x * x)
|
|
|
|
.fold(0, |x, y| x + y)
|
2016-03-21 04:19:07 -05:00
|
|
|
}
|
2016-04-06 18:29:56 -05:00
|
|
|
|
|
|
|
fn vec_reallocate() -> Vec<u8> {
|
2016-09-13 21:13:30 -05:00
|
|
|
let mut v = miri_vec![1, 2];
|
2016-04-06 18:29:56 -05:00
|
|
|
v.push(3);
|
|
|
|
v.push(4);
|
|
|
|
v.push(5);
|
|
|
|
v
|
|
|
|
}
|
2016-04-22 03:34:14 -05:00
|
|
|
|
2016-04-22 07:38:46 -05:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(vec_reallocate().len(), 5);
|
|
|
|
assert_eq!(vec_into_iter(), 30);
|
|
|
|
assert_eq!(make_vec().capacity(), 4);
|
2016-06-13 07:27:05 -05:00
|
|
|
assert_eq!(make_vec_macro(), [1, 2]);
|
|
|
|
assert_eq!(make_vec_macro_repeat(), [42; 5]);
|
2016-04-22 07:38:46 -05:00
|
|
|
}
|