about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-08-18 18:34:35 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-08-24 21:32:48 +0200
commit6498959377421876040515af39b6491a2ec2a0c5 (patch)
tree2ef5b481ec392fba10c7b3e0350e65e2d9054342
parentdc5bbaf7b2df8dc2be6c0f1a9973867e5519300b (diff)
downloadrust-6498959377421876040515af39b6491a2ec2a0c5.tar.gz
rust-6498959377421876040515af39b6491a2ec2a0c5.zip
parser: use `eat_or_separator` for leading vert.
-rw-r--r--src/libsyntax/parse/parser/pat.rs4
-rw-r--r--src/test/ui/or-patterns/multiple-pattern-typo.rs5
-rw-r--r--src/test/ui/or-patterns/multiple-pattern-typo.stderr8
3 files changed, 14 insertions, 3 deletions
diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs
index 14ac509d6f7..1063e347530 100644
--- a/src/libsyntax/parse/parser/pat.rs
+++ b/src/libsyntax/parse/parser/pat.rs
@@ -22,8 +22,8 @@ impl<'a> Parser<'a> {
 
     /// Parses patterns, separated by '|' s.
     pub(super) fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> {
-        // Allow a '|' before the pats (RFC 1925 + RFC 2530)
-        self.eat(&token::BinOp(token::Or));
+        // Allow a '|' before the pats (RFCs 1925, 2530, and 2535).
+        self.eat_or_separator();
 
         let mut pats = Vec::new();
         loop {
diff --git a/src/test/ui/or-patterns/multiple-pattern-typo.rs b/src/test/ui/or-patterns/multiple-pattern-typo.rs
index 5d1da56674b..e308c0adb4e 100644
--- a/src/test/ui/or-patterns/multiple-pattern-typo.rs
+++ b/src/test/ui/or-patterns/multiple-pattern-typo.rs
@@ -37,4 +37,9 @@ fn main() {
         [1 | 2 || 3] => (), //~ ERROR unexpected token `||` after pattern
         _ => (),
     }
+
+    match x {
+        || 1 | 2 | 3 => (), //~ ERROR unexpected token `||` after pattern
+        _ => (),
+    }
 }
diff --git a/src/test/ui/or-patterns/multiple-pattern-typo.stderr b/src/test/ui/or-patterns/multiple-pattern-typo.stderr
index 97f3470a54a..765c7879b12 100644
--- a/src/test/ui/or-patterns/multiple-pattern-typo.stderr
+++ b/src/test/ui/or-patterns/multiple-pattern-typo.stderr
@@ -34,6 +34,12 @@ error: unexpected token `||` after pattern
 LL |         [1 | 2 || 3] => (),
    |                ^^ help: use a single `|` to specify multiple patterns: `|`
 
+error: unexpected token `||` after pattern
+  --> $DIR/multiple-pattern-typo.rs:42:9
+   |
+LL |         || 1 | 2 | 3 => (),
+   |         ^^ help: use a single `|` to specify multiple patterns: `|`
+
 warning: the feature `or_patterns` is incomplete and may cause the compiler to crash
   --> $DIR/multiple-pattern-typo.rs:1:12
    |
@@ -42,5 +48,5 @@ LL | #![feature(or_patterns)]
    |
    = note: `#[warn(incomplete_features)]` on by default
 
-error: aborting due to 6 previous errors
+error: aborting due to 7 previous errors