]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/pat-tuple-6.rs
New upstream version 1.14.0+dfsg1
[rustc.git] / src / test / run-pass / pat-tuple-6.rs
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
11 fn tuple() {
12 let x = (1, 2, 3, 4, 5);
13 match x {
14 (a, .., b, c) => {
15 assert_eq!(a, 1);
16 assert_eq!(b, 4);
17 assert_eq!(c, 5);
18 }
19 }
20 match x {
21 (a, b, c, .., d) => {
22 assert_eq!(a, 1);
23 assert_eq!(b, 2);
24 assert_eq!(c, 3);
25 assert_eq!(d, 5);
26 }
27 }
28 }
29
30 fn tuple_struct() {
31 struct S(u8, u8, u8, u8, u8);
32
33 let x = S(1, 2, 3, 4, 5);
34 match x {
35 S(a, .., b, c) => {
36 assert_eq!(a, 1);
37 assert_eq!(b, 4);
38 assert_eq!(c, 5);
39 }
40 }
41 match x {
42 S(a, b, c, .., d) => {
43 assert_eq!(a, 1);
44 assert_eq!(b, 2);
45 assert_eq!(c, 3);
46 assert_eq!(d, 5);
47 }
48 }
49 }
50
51 fn main() {
52 tuple();
53 tuple_struct();
54 }