rust/src/test/run-pass/vec-matching.rs

55 lines
1.1 KiB
Rust
Raw Normal View History

fn a() {
let x = [1];
match x {
[_, _, _, _, _, .._] => ::std::util::unreachable(),
[.._, _, _, _, _] => ::std::util::unreachable(),
[_, .._, _, _] => ::std::util::unreachable(),
[_, _] => ::std::util::unreachable(),
[a] => {
assert_eq!(a, 1);
}
[] => ::std::util::unreachable()
}
}
fn b() {
let x = [1, 2, 3];
match x {
[a, b, ..c] => {
assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(c, &[3]);
}
_ => fail!()
}
match x {
[..a, b, c] => {
assert_eq!(a, &[1]);
assert_eq!(b, 2);
assert_eq!(c, 3);
}
_ => fail!()
}
match x {
[a, ..b, c] => {
assert_eq!(a, 1);
assert_eq!(b, &[2]);
assert_eq!(c, 3);
}
_ => fail!()
}
match x {
[a, b, c] => {
assert_eq!(a, 1);
assert_eq!(b, 2);
assert_eq!(c, 3);
}
_ => fail!()
}
}
pub fn main() {
a();
b();
}