]>
Commit | Line | Data |
---|---|---|
3157f602 XL |
1 | // Copyright 2016 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 | ||
b7449926 | 11 | // run-pass |
3157f602 XL |
12 | fn tuple() { |
13 | let x = (1, 2, 3); | |
14 | match x { | |
15 | (a, b, ..) => { | |
16 | assert_eq!(a, 1); | |
17 | assert_eq!(b, 2); | |
18 | } | |
19 | } | |
20 | match x { | |
21 | (.., b, c) => { | |
22 | assert_eq!(b, 2); | |
23 | assert_eq!(c, 3); | |
24 | } | |
25 | } | |
26 | match x { | |
27 | (a, .., c) => { | |
28 | assert_eq!(a, 1); | |
29 | assert_eq!(c, 3); | |
30 | } | |
31 | } | |
32 | match x { | |
33 | (a, b, c) => { | |
34 | assert_eq!(a, 1); | |
35 | assert_eq!(b, 2); | |
36 | assert_eq!(c, 3); | |
37 | } | |
38 | } | |
39 | match x { | |
40 | (a, b, c, ..) => { | |
41 | assert_eq!(a, 1); | |
42 | assert_eq!(b, 2); | |
43 | assert_eq!(c, 3); | |
44 | } | |
45 | } | |
46 | match x { | |
47 | (.., a, b, c) => { | |
48 | assert_eq!(a, 1); | |
49 | assert_eq!(b, 2); | |
50 | assert_eq!(c, 3); | |
51 | } | |
52 | } | |
53 | } | |
54 | ||
55 | fn tuple_struct() { | |
56 | struct S(u8, u8, u8); | |
57 | ||
58 | let x = S(1, 2, 3); | |
59 | match x { | |
60 | S(a, b, ..) => { | |
61 | assert_eq!(a, 1); | |
62 | assert_eq!(b, 2); | |
63 | } | |
64 | } | |
65 | match x { | |
66 | S(.., b, c) => { | |
67 | assert_eq!(b, 2); | |
68 | assert_eq!(c, 3); | |
69 | } | |
70 | } | |
71 | match x { | |
72 | S(a, .., c) => { | |
73 | assert_eq!(a, 1); | |
74 | assert_eq!(c, 3); | |
75 | } | |
76 | } | |
77 | match x { | |
78 | S(a, b, c) => { | |
79 | assert_eq!(a, 1); | |
80 | assert_eq!(b, 2); | |
81 | assert_eq!(c, 3); | |
82 | } | |
83 | } | |
84 | match x { | |
85 | S(a, b, c, ..) => { | |
86 | assert_eq!(a, 1); | |
87 | assert_eq!(b, 2); | |
88 | assert_eq!(c, 3); | |
89 | } | |
90 | } | |
91 | match x { | |
92 | S(.., a, b, c) => { | |
93 | assert_eq!(a, 1); | |
94 | assert_eq!(b, 2); | |
95 | assert_eq!(c, 3); | |
96 | } | |
97 | } | |
98 | } | |
99 | ||
100 | fn main() { | |
101 | tuple(); | |
102 | tuple_struct(); | |
103 | } |