Rollup merge of #33639 - petrochenkov:dotdot, r=nmatsakis
cc https://github.com/rust-lang/rust/issues/33627 r? @nikomatsakis plugin-[breaking-change] cc https://github.com/rust-lang/rust/issues/31645 @Manishearth
This commit is contained in:
commit
35785712cd
50 changed files with 873 additions and 297 deletions
|
|
@ -18,12 +18,12 @@ struct S;
|
|||
fn main() {
|
||||
match Foo::Baz {
|
||||
Foo::Bar => {}
|
||||
//~^ ERROR this pattern has 0 fields, but the corresponding variant
|
||||
//~^ ERROR `Foo::Bar` does not name a tuple variant or a tuple struct
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match S {
|
||||
S(()) => {}
|
||||
//~^ ERROR this pattern has 1 field, but the corresponding struct
|
||||
//~^ ERROR `S` does not name a tuple variant or a tuple struct
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ fn main() {
|
|||
color::rgb(_, _, _) => { }
|
||||
color::cmyk(_, _, _, _) => { }
|
||||
color::no_color(_) => { }
|
||||
//~^ ERROR this pattern has 1 field, but the corresponding variant has no fields
|
||||
//~^ ERROR `color::no_color` does not name a tuple variant or a tuple struct
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
src/test/compile-fail/pat-tuple-bad-type.rs
Normal file
27
src/test/compile-fail/pat-tuple-bad-type.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
fn main() {
|
||||
let x;
|
||||
|
||||
match x {
|
||||
(..) => {} //~ ERROR the type of this value must be known in this context
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match 0u8 {
|
||||
(..) => {} //~ ERROR mismatched types
|
||||
_ => {}
|
||||
}
|
||||
|
||||
x = 10;
|
||||
}
|
||||
17
src/test/compile-fail/pat-tuple-feature-gate.rs
Normal file
17
src/test/compile-fail/pat-tuple-feature-gate.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
match 0 {
|
||||
(..) => {} //~ ERROR `..` in tuple patterns is experimental
|
||||
(pat, ..) => {} //~ ERROR `..` in tuple patterns is experimental
|
||||
S(pat, ..) => {} //~ ERROR `..` in tuple struct patterns is experimental
|
||||
}
|
||||
}
|
||||
28
src/test/compile-fail/pat-tuple-overfield.rs
Normal file
28
src/test/compile-fail/pat-tuple-overfield.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
struct S(u8, u8, u8);
|
||||
|
||||
fn main() {
|
||||
match (1, 2, 3) {
|
||||
(1, 2, 3, 4) => {} //~ ERROR mismatched types
|
||||
(1, 2, .., 3, 4) => {} //~ ERROR mismatched types
|
||||
_ => {}
|
||||
}
|
||||
match S(1, 2, 3) {
|
||||
S(1, 2, 3, 4) => {}
|
||||
//~^ ERROR this pattern has 4 fields, but the corresponding struct has 3 fields
|
||||
S(1, 2, .., 3, 4) => {}
|
||||
//~^ ERROR this pattern has 4 fields, but the corresponding struct has 3 fields
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
|
@ -25,7 +25,7 @@ fn f(_c: char) {}
|
|||
fn main() {
|
||||
match A::B(1, 2) {
|
||||
A::B(_, _, _) => (), //~ ERROR this pattern has 3 fields, but
|
||||
A::D(_) => (), //~ ERROR this pattern has 1 field, but
|
||||
A::D(_) => (), //~ ERROR `A::D` does not name a tuple variant or a tuple struct
|
||||
_ => ()
|
||||
}
|
||||
match 'c' {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,5 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let Test(&desc[..]) = x; //~ error: expected one of `,` or `@`, found `[`
|
||||
//~^ ERROR expected one of `:`, `;`, `=`, or `@`, found `[`
|
||||
let Test(&desc[..]) = x; //~ ERROR: expected one of `)`, `,`, or `@`, found `[`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,5 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
for thing(x[]) in foo {} //~ error: expected one of `,` or `@`, found `[`
|
||||
//~^ ERROR expected one of `@` or `in`, found `[`
|
||||
for thing(x[]) in foo {} //~ ERROR: expected one of `)`, `,`, or `@`, found `[`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,15 +8,10 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
enum Number {
|
||||
Zero,
|
||||
One(u32)
|
||||
}
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
fn main() {
|
||||
let x = Number::Zero;
|
||||
match x {
|
||||
Number::Zero(inside) => {}, //~ ERROR E0024
|
||||
Number::One(inside) => {},
|
||||
match 0 {
|
||||
(, ..) => {} //~ ERROR expected pattern, found `,`
|
||||
}
|
||||
}
|
||||
17
src/test/parse-fail/pat-tuple-2.rs
Normal file
17
src/test/parse-fail/pat-tuple-2.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
fn main() {
|
||||
match 0 {
|
||||
(pat, ..,) => {} //~ ERROR expected pattern, found `)`
|
||||
}
|
||||
}
|
||||
17
src/test/parse-fail/pat-tuple-3.rs
Normal file
17
src/test/parse-fail/pat-tuple-3.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
fn main() {
|
||||
match 0 {
|
||||
(.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern
|
||||
}
|
||||
}
|
||||
17
src/test/parse-fail/pat-tuple-4.rs
Normal file
17
src/test/parse-fail/pat-tuple-4.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
fn main() {
|
||||
match 0 {
|
||||
(.. pat) => {} //~ ERROR expected one of `)` or `,`, found `pat`
|
||||
}
|
||||
}
|
||||
17
src/test/parse-fail/pat-tuple-5.rs
Normal file
17
src/test/parse-fail/pat-tuple-5.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
fn main() {
|
||||
match 0 {
|
||||
(pat ..) => {} //~ ERROR expected one of `)`, `,`, or `@`, found `..`
|
||||
}
|
||||
}
|
||||
17
src/test/parse-fail/pat-tuple-6.rs
Normal file
17
src/test/parse-fail/pat-tuple-6.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-flags: -Z parse-only
|
||||
|
||||
fn main() {
|
||||
match 0 {
|
||||
(pat) => {} //~ ERROR expected one of `,` or `@`, found `)`
|
||||
}
|
||||
}
|
||||
104
src/test/run-pass/pat-tuple-1.rs
Normal file
104
src/test/run-pass/pat-tuple-1.rs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
fn tuple() {
|
||||
let x = (1, 2, 3);
|
||||
match x {
|
||||
(a, b, ..) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
(.., b, c) => {
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
(a, .., c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
(a, b, c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
(a, b, c, ..) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
(.., a, b, c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tuple_struct() {
|
||||
struct S(u8, u8, u8);
|
||||
|
||||
let x = S(1, 2, 3);
|
||||
match x {
|
||||
S(a, b, ..) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
S(.., b, c) => {
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
S(a, .., c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
S(a, b, c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
S(a, b, c, ..) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
S(.., a, b, c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tuple();
|
||||
tuple_struct();
|
||||
}
|
||||
34
src/test/run-pass/pat-tuple-2.rs
Normal file
34
src/test/run-pass/pat-tuple-2.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
fn tuple() {
|
||||
let x = (1,);
|
||||
match x {
|
||||
(2, ..) => panic!(),
|
||||
(..) => ()
|
||||
}
|
||||
}
|
||||
|
||||
fn tuple_struct() {
|
||||
struct S(u8);
|
||||
|
||||
let x = S(1);
|
||||
match x {
|
||||
S(2, ..) => panic!(),
|
||||
S(..) => ()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tuple();
|
||||
tuple_struct();
|
||||
}
|
||||
40
src/test/run-pass/pat-tuple-3.rs
Normal file
40
src/test/run-pass/pat-tuple-3.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
fn tuple() {
|
||||
let x = (1, 2, 3);
|
||||
let branch = match x {
|
||||
(1, 1, ..) => 0,
|
||||
(1, 2, 3, ..) => 1,
|
||||
(1, 2, ..) => 2,
|
||||
_ => 3
|
||||
};
|
||||
assert_eq!(branch, 1);
|
||||
}
|
||||
|
||||
fn tuple_struct() {
|
||||
struct S(u8, u8, u8);
|
||||
|
||||
let x = S(1, 2, 3);
|
||||
let branch = match x {
|
||||
S(1, 1, ..) => 0,
|
||||
S(1, 2, 3, ..) => 1,
|
||||
S(1, 2, ..) => 2,
|
||||
_ => 3
|
||||
};
|
||||
assert_eq!(branch, 1);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tuple();
|
||||
tuple_struct();
|
||||
}
|
||||
68
src/test/run-pass/pat-tuple-4.rs
Normal file
68
src/test/run-pass/pat-tuple-4.rs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
fn tuple() {
|
||||
let x = (1, 2, 3);
|
||||
match x {
|
||||
(1, 2, 4) => unreachable!(),
|
||||
(0, 2, 3, ..) => unreachable!(),
|
||||
(0, .., 3) => unreachable!(),
|
||||
(0, ..) => unreachable!(),
|
||||
(1, 2, 3) => (),
|
||||
(_, _, _) => unreachable!(),
|
||||
}
|
||||
match x {
|
||||
(..) => (),
|
||||
}
|
||||
match x {
|
||||
(_, _, _, ..) => (),
|
||||
}
|
||||
match x {
|
||||
(a, b, c) => {
|
||||
assert_eq!(1, a);
|
||||
assert_eq!(2, b);
|
||||
assert_eq!(3, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tuple_struct() {
|
||||
struct S(u8, u8, u8);
|
||||
|
||||
let x = S(1, 2, 3);
|
||||
match x {
|
||||
S(1, 2, 4) => unreachable!(),
|
||||
S(0, 2, 3, ..) => unreachable!(),
|
||||
S(0, .., 3) => unreachable!(),
|
||||
S(0, ..) => unreachable!(),
|
||||
S(1, 2, 3) => (),
|
||||
S(_, _, _) => unreachable!(),
|
||||
}
|
||||
match x {
|
||||
S(..) => (),
|
||||
}
|
||||
match x {
|
||||
S(_, _, _, ..) => (),
|
||||
}
|
||||
match x {
|
||||
S(a, b, c) => {
|
||||
assert_eq!(1, a);
|
||||
assert_eq!(2, b);
|
||||
assert_eq!(3, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tuple();
|
||||
tuple_struct();
|
||||
}
|
||||
40
src/test/run-pass/pat-tuple-5.rs
Normal file
40
src/test/run-pass/pat-tuple-5.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
fn tuple() {
|
||||
struct S;
|
||||
struct Z;
|
||||
struct W;
|
||||
let x = (S, Z, W);
|
||||
match x { (S, ..) => {} }
|
||||
match x { (.., W) => {} }
|
||||
match x { (S, .., W) => {} }
|
||||
match x { (.., Z, _) => {} }
|
||||
}
|
||||
|
||||
fn tuple_struct() {
|
||||
struct SS(S, Z, W);
|
||||
|
||||
struct S;
|
||||
struct Z;
|
||||
struct W;
|
||||
let x = SS(S, Z, W);
|
||||
match x { SS(S, ..) => {} }
|
||||
match x { SS(.., W) => {} }
|
||||
match x { SS(S, .., W) => {} }
|
||||
match x { SS(.., Z, _) => {} }
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tuple();
|
||||
tuple_struct();
|
||||
}
|
||||
56
src/test/run-pass/pat-tuple-6.rs
Normal file
56
src/test/run-pass/pat-tuple-6.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(dotdot_in_tuple_patterns)]
|
||||
|
||||
fn tuple() {
|
||||
let x = (1, 2, 3, 4, 5);
|
||||
match x {
|
||||
(a, .., b, c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 4);
|
||||
assert_eq!(c, 5);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
(a, b, c, .., d) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
assert_eq!(d, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn tuple_struct() {
|
||||
struct S(u8, u8, u8, u8, u8);
|
||||
|
||||
let x = S(1, 2, 3, 4, 5);
|
||||
match x {
|
||||
S(a, .., b, c) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 4);
|
||||
assert_eq!(c, 5);
|
||||
}
|
||||
}
|
||||
match x {
|
||||
S(a, b, c, .., d) => {
|
||||
assert_eq!(a, 1);
|
||||
assert_eq!(b, 2);
|
||||
assert_eq!(c, 3);
|
||||
assert_eq!(d, 5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tuple();
|
||||
tuple_struct();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue