|
| 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 | +#![feature(dotdot_in_tuple_patterns)] |
| 12 | + |
| 13 | +fn tuple() { |
| 14 | + let x = (1, 2, 3); |
| 15 | + match x { |
| 16 | + (1, 2, 4) => unreachable!(), |
| 17 | + (0, 2, 3, ..) => unreachable!(), |
| 18 | + (0, .., 3) => unreachable!(), |
| 19 | + (0, ..) => unreachable!(), |
| 20 | + (1, 2, 3) => (), |
| 21 | + (_, _, _) => unreachable!(), |
| 22 | + } |
| 23 | + match x { |
| 24 | + (..) => (), |
| 25 | + } |
| 26 | + match x { |
| 27 | + (_, _, _, ..) => (), |
| 28 | + } |
| 29 | + match x { |
| 30 | + (a, b, c) => { |
| 31 | + assert_eq!(1, a); |
| 32 | + assert_eq!(2, b); |
| 33 | + assert_eq!(3, c); |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +fn tuple_struct() { |
| 39 | + struct S(u8, u8, u8); |
| 40 | + |
| 41 | + let x = S(1, 2, 3); |
| 42 | + match x { |
| 43 | + S(1, 2, 4) => unreachable!(), |
| 44 | + S(0, 2, 3, ..) => unreachable!(), |
| 45 | + S(0, .., 3) => unreachable!(), |
| 46 | + S(0, ..) => unreachable!(), |
| 47 | + S(1, 2, 3) => (), |
| 48 | + S(_, _, _) => unreachable!(), |
| 49 | + } |
| 50 | + match x { |
| 51 | + S(..) => (), |
| 52 | + } |
| 53 | + match x { |
| 54 | + S(_, _, _, ..) => (), |
| 55 | + } |
| 56 | + match x { |
| 57 | + S(a, b, c) => { |
| 58 | + assert_eq!(1, a); |
| 59 | + assert_eq!(2, b); |
| 60 | + assert_eq!(3, c); |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +fn main() { |
| 66 | + tuple(); |
| 67 | + tuple_struct(); |
| 68 | +} |
0 commit comments