]> git.lizzy.rs Git - rust.git/blob - src/test/ui/array-slice-vec/vec-tail-matching.rs
Simplify SaveHandler trait
[rust.git] / src / test / ui / array-slice-vec / vec-tail-matching.rs
1 // run-pass
2
3 #![feature(slice_patterns)]
4
5 struct Foo {
6     string: &'static str
7 }
8
9 pub fn main() {
10     let x = [
11         Foo { string: "foo" },
12         Foo { string: "bar" },
13         Foo { string: "baz" }
14     ];
15     match x {
16         [ref first, ref tail..] => {
17             assert_eq!(first.string, "foo");
18             assert_eq!(tail.len(), 2);
19             assert_eq!(tail[0].string, "bar");
20             assert_eq!(tail[1].string, "baz");
21
22             match *(tail as &[_]) {
23                 [Foo { .. }, _, Foo { .. }, ref _tail..] => {
24                     unreachable!();
25                 }
26                 [Foo { string: ref a }, Foo { string: ref b }] => {
27                     assert_eq!("bar", &a[0..a.len()]);
28                     assert_eq!("baz", &b[0..b.len()]);
29                 }
30                 _ => {
31                     unreachable!();
32                 }
33             }
34         }
35     }
36 }