]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | ||
c34b1796 AL |
11 | // pretty-expanded FIXME #23616 |
12 | ||
1a4d82fc | 13 | #![feature(advanced_slice_patterns)] |
c34b1796 | 14 | #![feature(slice_patterns)] |
1a4d82fc | 15 | |
223e47cc | 16 | fn a() { |
85aaf69f | 17 | let x = [1]; |
223e47cc | 18 | match x { |
223e47cc | 19 | [a] => { |
970d7e83 | 20 | assert_eq!(a, 1); |
223e47cc | 21 | } |
223e47cc LB |
22 | } |
23 | } | |
24 | ||
25 | fn b() { | |
85aaf69f | 26 | let x = [1, 2, 3]; |
223e47cc | 27 | match x { |
1a4d82fc | 28 | [a, b, c..] => { |
970d7e83 LB |
29 | assert_eq!(a, 1); |
30 | assert_eq!(b, 2); | |
1a4d82fc JJ |
31 | let expected: &[_] = &[3]; |
32 | assert_eq!(c, expected); | |
223e47cc | 33 | } |
223e47cc LB |
34 | } |
35 | match x { | |
1a4d82fc JJ |
36 | [a.., b, c] => { |
37 | let expected: &[_] = &[1]; | |
38 | assert_eq!(a, expected); | |
970d7e83 LB |
39 | assert_eq!(b, 2); |
40 | assert_eq!(c, 3); | |
223e47cc | 41 | } |
223e47cc LB |
42 | } |
43 | match x { | |
1a4d82fc | 44 | [a, b.., c] => { |
970d7e83 | 45 | assert_eq!(a, 1); |
1a4d82fc JJ |
46 | let expected: &[_] = &[2]; |
47 | assert_eq!(b, expected); | |
970d7e83 | 48 | assert_eq!(c, 3); |
223e47cc | 49 | } |
223e47cc LB |
50 | } |
51 | match x { | |
52 | [a, b, c] => { | |
970d7e83 LB |
53 | assert_eq!(a, 1); |
54 | assert_eq!(b, 2); | |
55 | assert_eq!(c, 3); | |
223e47cc | 56 | } |
1a4d82fc JJ |
57 | } |
58 | } | |
59 | ||
60 | fn c() { | |
85aaf69f | 61 | let x = [1]; |
1a4d82fc JJ |
62 | match x { |
63 | [2, ..] => panic!(), | |
64 | [..] => () | |
65 | } | |
66 | } | |
67 | ||
68 | fn d() { | |
85aaf69f | 69 | let x = [1, 2, 3]; |
1a4d82fc | 70 | let branch = match x { |
85aaf69f SL |
71 | [1, 1, ..] => 0, |
72 | [1, 2, 3, ..] => 1, | |
73 | [1, 2, ..] => 2, | |
1a4d82fc JJ |
74 | _ => 3 |
75 | }; | |
76 | assert_eq!(branch, 1); | |
77 | } | |
78 | ||
79 | fn e() { | |
c34b1796 | 80 | let x: &[isize] = &[1, 2, 3]; |
1a4d82fc JJ |
81 | match x { |
82 | [1, 2] => (), | |
83 | [..] => () | |
223e47cc LB |
84 | } |
85 | } | |
86 | ||
87 | pub fn main() { | |
88 | a(); | |
89 | b(); | |
1a4d82fc JJ |
90 | c(); |
91 | d(); | |
92 | e(); | |
223e47cc | 93 | } |