53 lines
991 B
Rust
Raw Normal View History

2017-09-16 13:32:38 +02:00
//ignore-msvc
fn make_vec() -> Vec<u8> {
2016-03-21 02:41:07 -06:00
let mut v = Vec::with_capacity(4);
2016-03-20 20:18:09 -06:00
v.push(1);
v.push(2);
v
}
fn make_vec_macro() -> Vec<u8> {
vec![1, 2]
2016-03-21 02:41:22 -06:00
}
2016-03-21 03:19:07 -06:00
fn make_vec_macro_repeat() -> Vec<u8> {
vec![42; 5]
}
fn make_vec_macro_repeat_zeroed() -> Vec<u8> {
vec![0; 7]
}
fn vec_into_iter() -> u8 {
vec![1, 2, 3, 4]
.into_iter()
.map(|x| x * x)
.fold(0, |x, y| x + y)
2016-03-21 03:19:07 -06:00
}
2017-07-20 13:20:33 -07:00
fn vec_into_iter_zst() -> usize {
vec![[0u64; 0], [0u64; 0]]
.into_iter()
.map(|x| x.len())
.sum()
}
fn vec_reallocate() -> Vec<u8> {
let mut v = vec![1, 2];
v.push(3);
v.push(4);
v.push(5);
v
}
2016-04-22 10:34:14 +02:00
2016-04-22 14:38:46 +02:00
fn main() {
assert_eq!(vec_reallocate().len(), 5);
assert_eq!(vec_into_iter(), 30);
2017-07-20 13:20:33 -07:00
assert_eq!(vec_into_iter_zst(), 0);
2016-04-22 14:38:46 +02:00
assert_eq!(make_vec().capacity(), 4);
assert_eq!(make_vec_macro(), [1, 2]);
assert_eq!(make_vec_macro_repeat(), [42; 5]);
assert_eq!(make_vec_macro_repeat_zeroed(), [0; 7]);
2016-04-22 14:38:46 +02:00
}