2018-08-30 14:18:55 +02:00
|
|
|
//@ run-pass
|
|
|
|
|
2012-12-08 20:22:43 +00:00
|
|
|
struct Foo {
|
2016-03-11 12:54:59 +02:00
|
|
|
string: &'static str
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2014-02-13 09:46:46 -08:00
|
|
|
let x = [
|
2016-03-11 12:54:59 +02:00
|
|
|
Foo { string: "foo" },
|
|
|
|
Foo { string: "bar" },
|
|
|
|
Foo { string: "baz" }
|
2012-12-08 20:22:43 +00:00
|
|
|
];
|
|
|
|
match x {
|
2019-07-08 01:47:46 +02:00
|
|
|
[ref first, ref tail @ ..] => {
|
2016-03-11 12:54:59 +02:00
|
|
|
assert_eq!(first.string, "foo");
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(tail.len(), 2);
|
2016-03-11 12:54:59 +02:00
|
|
|
assert_eq!(tail[0].string, "bar");
|
|
|
|
assert_eq!(tail[1].string, "baz");
|
2012-12-08 20:22:43 +00:00
|
|
|
|
2016-03-11 12:54:59 +02:00
|
|
|
match *(tail as &[_]) {
|
2019-07-08 01:47:46 +02:00
|
|
|
[Foo { .. }, _, Foo { .. }, ref _tail @ ..] => {
|
2013-09-19 15:04:03 +10:00
|
|
|
unreachable!();
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
2013-05-22 06:54:35 -04:00
|
|
|
[Foo { string: ref a }, Foo { string: ref b }] => {
|
2015-01-26 21:21:15 -05:00
|
|
|
assert_eq!("bar", &a[0..a.len()]);
|
|
|
|
assert_eq!("baz", &b[0..b.len()]);
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
|
|
|
_ => {
|
2013-09-19 15:04:03 +10:00
|
|
|
unreachable!();
|
2012-12-08 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|