2013-03-11 05:53:41 -05:00
|
|
|
fn a() {
|
2013-02-26 12:58:46 -06:00
|
|
|
let x = [1];
|
2012-12-08 14:22:43 -06:00
|
|
|
match x {
|
2013-05-20 19:07:24 -05:00
|
|
|
[_, _, _, _, _, .._] => ::std::util::unreachable(),
|
|
|
|
[.._, _, _, _, _] => ::std::util::unreachable(),
|
|
|
|
[_, .._, _, _] => ::std::util::unreachable(),
|
|
|
|
[_, _] => ::std::util::unreachable(),
|
2013-02-26 12:58:46 -06:00
|
|
|
[a] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
2013-05-20 19:07:24 -05:00
|
|
|
[] => ::std::util::unreachable()
|
2012-12-08 14:22:43 -06:00
|
|
|
}
|
|
|
|
}
|
2013-03-11 05:53:41 -05:00
|
|
|
|
|
|
|
fn b() {
|
|
|
|
let x = [1, 2, 3];
|
|
|
|
match x {
|
|
|
|
[a, b, ..c] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
|
|
|
assert_eq!(b, 2);
|
|
|
|
assert_eq!(c, &[3]);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
_ => fail!()
|
|
|
|
}
|
|
|
|
match x {
|
|
|
|
[..a, b, c] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, &[1]);
|
|
|
|
assert_eq!(b, 2);
|
|
|
|
assert_eq!(c, 3);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
_ => fail!()
|
|
|
|
}
|
|
|
|
match x {
|
|
|
|
[a, ..b, c] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
|
|
|
assert_eq!(b, &[2]);
|
|
|
|
assert_eq!(c, 3);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
_ => fail!()
|
|
|
|
}
|
|
|
|
match x {
|
|
|
|
[a, b, c] => {
|
2013-05-18 21:02:45 -05:00
|
|
|
assert_eq!(a, 1);
|
|
|
|
assert_eq!(b, 2);
|
|
|
|
assert_eq!(c, 3);
|
2013-03-11 05:53:41 -05:00
|
|
|
}
|
|
|
|
_ => fail!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
a();
|
|
|
|
b();
|
|
|
|
}
|