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