parse_top_pat: silence leading vert gating sometimes.

This commit is contained in:
Mazdak Farrokhzad 2019-08-24 22:46:17 +02:00
parent a9ef8592e4
commit 3a405421e7
8 changed files with 80 additions and 36 deletions

View File

@ -46,11 +46,23 @@ impl<'a> Parser<'a> {
/// Corresponds to `top_pat` in RFC 2535 and allows or-pattern at the top level.
pub(super) fn parse_top_pat(&mut self, gate_or: GateOr) -> PResult<'a, P<Pat>> {
// Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
if self.eat_or_separator() && gate_or == GateOr::Yes {
self.sess.gated_spans.or_patterns.borrow_mut().push(self.prev_span);
let gated_leading_vert = self.eat_or_separator() && gate_or == GateOr::Yes;
// Parse the possibly-or-pattern.
let pat = self.parse_pat_with_or(None, gate_or, TopLevel::Yes)?;
// If we parsed a leading `|` which should be gated,
// and no other gated or-pattern has been parsed thus far,
// then we should really gate the leading `|`.
// This complicated procedure is done purely for diagnostics UX.
if gated_leading_vert {
let mut or_pattern_spans = self.sess.gated_spans.or_patterns.borrow_mut();
if or_pattern_spans.is_empty() {
or_pattern_spans.push(self.prev_span);
}
}
self.parse_pat_with_or(None, gate_or, TopLevel::Yes)
Ok(pat)
}
/// Parses a pattern, that may be a or-pattern (e.g. `Foo | Bar` in `Some(Foo | Bar)`).

View File

@ -0,0 +1,8 @@
// Test feature gating for a sole leading `|` in `let`.
fn main() {}
#[cfg(FALSE)]
fn gated_leading_vert_in_let() {
for | A in 0 {} //~ ERROR or-patterns syntax is experimental
}

View File

@ -0,0 +1,12 @@
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns-leading-for.rs:7:11
|
LL | for | A in 0 {}
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54883
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -0,0 +1,8 @@
// Test feature gating for a sole leading `|` in `let`.
fn main() {}
#[cfg(FALSE)]
fn gated_leading_vert_in_let() {
let | A; //~ ERROR or-patterns syntax is experimental
}

View File

@ -0,0 +1,12 @@
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns-leading-let.rs:7:11
|
LL | let | A;
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54883
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -0,0 +1,12 @@
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns-leading.rs:7:11
|
LL | let | A;
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54883
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -26,10 +26,8 @@ fn or_patterns() {
// Gated:
let | A | B; //~ ERROR or-patterns syntax is experimental
//~^ ERROR or-patterns syntax is experimental
let A | B; //~ ERROR or-patterns syntax is experimental
for | A | B in 0 {} //~ ERROR or-patterns syntax is experimental
//~^ ERROR or-patterns syntax is experimental
for A | B in 0 {} //~ ERROR or-patterns syntax is experimental
fn fun((A | B): _) {} //~ ERROR or-patterns syntax is experimental
let _ = |(A | B): u8| (); //~ ERROR or-patterns syntax is experimental

View File

@ -7,15 +7,6 @@ LL | Some(0 | 1 | 2) => {}
= note: for more information, see https://github.com/rust-lang/rust/issues/54883
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:28:9
|
LL | let | A | B;
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54883
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:28:11
|
@ -26,7 +17,7 @@ LL | let | A | B;
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:30:9
--> $DIR/feature-gate-or_patterns.rs:29:9
|
LL | let A | B;
| ^^^^^
@ -35,16 +26,7 @@ LL | let A | B;
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:31:9
|
LL | for | A | B in 0 {}
| ^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54883
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:31:11
--> $DIR/feature-gate-or_patterns.rs:30:11
|
LL | for | A | B in 0 {}
| ^^^^^
@ -53,7 +35,7 @@ LL | for | A | B in 0 {}
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:33:9
--> $DIR/feature-gate-or_patterns.rs:31:9
|
LL | for A | B in 0 {}
| ^^^^^
@ -62,7 +44,7 @@ LL | for A | B in 0 {}
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:34:13
--> $DIR/feature-gate-or_patterns.rs:32:13
|
LL | fn fun((A | B): _) {}
| ^^^^^
@ -71,7 +53,7 @@ LL | fn fun((A | B): _) {}
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:35:15
--> $DIR/feature-gate-or_patterns.rs:33:15
|
LL | let _ = |(A | B): u8| ();
| ^^^^^
@ -80,7 +62,7 @@ LL | let _ = |(A | B): u8| ();
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:36:10
--> $DIR/feature-gate-or_patterns.rs:34:10
|
LL | let (A | B);
| ^^^^^
@ -89,7 +71,7 @@ LL | let (A | B);
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:37:10
--> $DIR/feature-gate-or_patterns.rs:35:10
|
LL | let (A | B,);
| ^^^^^
@ -98,7 +80,7 @@ LL | let (A | B,);
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:38:11
--> $DIR/feature-gate-or_patterns.rs:36:11
|
LL | let A(B | C);
| ^^^^^
@ -107,7 +89,7 @@ LL | let A(B | C);
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:39:14
--> $DIR/feature-gate-or_patterns.rs:37:14
|
LL | let E::V(B | C);
| ^^^^^
@ -116,7 +98,7 @@ LL | let E::V(B | C);
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:40:17
--> $DIR/feature-gate-or_patterns.rs:38:17
|
LL | let S { f1: B | C, f2 };
| ^^^^^
@ -125,7 +107,7 @@ LL | let S { f1: B | C, f2 };
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:41:20
--> $DIR/feature-gate-or_patterns.rs:39:20
|
LL | let E::V { f1: B | C, f2 };
| ^^^^^
@ -134,7 +116,7 @@ LL | let E::V { f1: B | C, f2 };
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error[E0658]: or-patterns syntax is experimental
--> $DIR/feature-gate-or_patterns.rs:42:10
--> $DIR/feature-gate-or_patterns.rs:40:10
|
LL | let [A | B];
| ^^^^^
@ -187,6 +169,6 @@ LL | accept_pat!([p | q]);
= note: for more information, see https://github.com/rust-lang/rust/issues/54883
= help: add `#![feature(or_patterns)]` to the crate attributes to enable
error: aborting due to 21 previous errors
error: aborting due to 19 previous errors
For more information about this error, try `rustc --explain E0658`.