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