]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/vec-tail-matching.rs
New upstream version 1.29.0+dfsg1
[rustc.git] / src / test / run-pass / vec-tail-matching.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(slice_patterns)]
12
13 struct Foo {
14 string: &'static str
15 }
16
17 pub fn main() {
18 let x = [
19 Foo { string: "foo" },
20 Foo { string: "bar" },
21 Foo { string: "baz" }
22 ];
23 match x {
24 [ref first, ref tail..] => {
25 assert_eq!(first.string, "foo");
26 assert_eq!(tail.len(), 2);
27 assert_eq!(tail[0].string, "bar");
28 assert_eq!(tail[1].string, "baz");
29
30 match *(tail as &[_]) {
31 [Foo { .. }, _, Foo { .. }, ref _tail..] => {
32 unreachable!();
33 }
34 [Foo { string: ref a }, Foo { string: ref b }] => {
35 assert_eq!("bar", &a[0..a.len()]);
36 assert_eq!("baz", &b[0..b.len()]);
37 }
38 _ => {
39 unreachable!();
40 }
41 }
42 }
43 }
44 }