From c9aff92e6dc3ea43228d3d4e24ee7f5485943569 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 24 Feb 2018 15:27:06 +0300 Subject: Support parentheses in patterns under feature gate Improve recovery for trailing comma after `..` --- src/test/parse-fail/pat-tuple-2.rs | 2 +- src/test/parse-fail/pat-tuple-6.rs | 17 ----------------- src/test/run-pass/pat-tuple-7.rs | 17 +++++++++++++++++ src/test/ui/feature-gate-pattern_parentheses.rs | 15 +++++++++++++++ src/test/ui/feature-gate-pattern_parentheses.stderr | 11 +++++++++++ 5 files changed, 44 insertions(+), 18 deletions(-) delete mode 100644 src/test/parse-fail/pat-tuple-6.rs create mode 100644 src/test/run-pass/pat-tuple-7.rs create mode 100644 src/test/ui/feature-gate-pattern_parentheses.rs create mode 100644 src/test/ui/feature-gate-pattern_parentheses.stderr (limited to 'src/test') diff --git a/src/test/parse-fail/pat-tuple-2.rs b/src/test/parse-fail/pat-tuple-2.rs index ad52fa57870..07b391d3279 100644 --- a/src/test/parse-fail/pat-tuple-2.rs +++ b/src/test/parse-fail/pat-tuple-2.rs @@ -12,6 +12,6 @@ fn main() { match 0 { - (pat, ..,) => {} //~ ERROR expected pattern, found `)` + (pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..` } } diff --git a/src/test/parse-fail/pat-tuple-6.rs b/src/test/parse-fail/pat-tuple-6.rs deleted file mode 100644 index 3252d92fe1b..00000000000 --- a/src/test/parse-fail/pat-tuple-6.rs +++ /dev/null @@ -1,17 +0,0 @@ -// 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 or the MIT license -// , 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 `)` - } -} diff --git a/src/test/run-pass/pat-tuple-7.rs b/src/test/run-pass/pat-tuple-7.rs new file mode 100644 index 00000000000..6d51df63e15 --- /dev/null +++ b/src/test/run-pass/pat-tuple-7.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(pattern_parentheses)] + +fn main() { + match 0 { + (pat) => assert_eq!(pat, 0) + } +} diff --git a/src/test/ui/feature-gate-pattern_parentheses.rs b/src/test/ui/feature-gate-pattern_parentheses.rs new file mode 100644 index 00000000000..29768018f0e --- /dev/null +++ b/src/test/ui/feature-gate-pattern_parentheses.rs @@ -0,0 +1,15 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + match 0 { + (pat) => {} //~ ERROR parentheses in patterns are unstable + } +} diff --git a/src/test/ui/feature-gate-pattern_parentheses.stderr b/src/test/ui/feature-gate-pattern_parentheses.stderr new file mode 100644 index 00000000000..4fc1441a0fa --- /dev/null +++ b/src/test/ui/feature-gate-pattern_parentheses.stderr @@ -0,0 +1,11 @@ +error[E0658]: parentheses in patterns are unstable + --> $DIR/feature-gate-pattern_parentheses.rs:13:9 + | +LL | (pat) => {} //~ ERROR parentheses in patterns are unstable + | ^^^^^ + | + = help: add #![feature(pattern_parentheses)] to the crate attributes to enable + +error: aborting due to previous error + +If you want more information on this error, try using "rustc --explain E0658" -- cgit 1.4.1-3-g733a5