]>
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, 4, 5); | |
14 | match x { | |
15 | (a, .., b, c) => { | |
16 | assert_eq!(a, 1); | |
17 | assert_eq!(b, 4); | |
18 | assert_eq!(c, 5); | |
19 | } | |
20 | } | |
21 | match x { | |
22 | (a, b, c, .., d) => { | |
23 | assert_eq!(a, 1); | |
24 | assert_eq!(b, 2); | |
25 | assert_eq!(c, 3); | |
26 | assert_eq!(d, 5); | |
27 | } | |
28 | } | |
29 | } | |
30 | ||
31 | fn tuple_struct() { | |
32 | struct S(u8, u8, u8, u8, u8); | |
33 | ||
34 | let x = S(1, 2, 3, 4, 5); | |
35 | match x { | |
36 | S(a, .., b, c) => { | |
37 | assert_eq!(a, 1); | |
38 | assert_eq!(b, 4); | |
39 | assert_eq!(c, 5); | |
40 | } | |
41 | } | |
42 | match x { | |
43 | S(a, b, c, .., d) => { | |
44 | assert_eq!(a, 1); | |
45 | assert_eq!(b, 2); | |
46 | assert_eq!(c, 3); | |
47 | assert_eq!(d, 5); | |
48 | } | |
49 | } | |
50 | } | |
51 | ||
52 | fn main() { | |
53 | tuple(); | |
54 | tuple_struct(); | |
55 | } |