about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-08-25 01:50:21 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-08-25 01:50:21 +0200
commit083963e58c752f1a51b67d65dc6a207bf69f1d64 (patch)
treea5274c7e6ffaa7f09d21d0f5c1d8782dfb2c5e36
parent1202cb0e2b168b0a913b33e3cb3c1d9339683e28 (diff)
downloadrust-083963e58c752f1a51b67d65dc6a207bf69f1d64.tar.gz
rust-083963e58c752f1a51b67d65dc6a207bf69f1d64.zip
parser: 'while parsing this or-pattern...'
-rw-r--r--src/libsyntax/parse/parser/pat.rs5
-rw-r--r--src/test/ui/or-patterns/while-parsing-this-or-pattern.rs9
-rw-r--r--src/test/ui/or-patterns/while-parsing-this-or-pattern.stderr10
3 files changed, 23 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs
index 7c09dc4e566..a0278fa4077 100644
--- a/src/libsyntax/parse/parser/pat.rs
+++ b/src/libsyntax/parse/parser/pat.rs
@@ -81,7 +81,10 @@ impl<'a> Parser<'a> {
         let lo = first_pat.span;
         let mut pats = vec![first_pat];
         while self.eat_or_separator() {
-            let pat = self.parse_pat(None)?;
+            let pat = self.parse_pat(None).map_err(|mut err| {
+                err.span_label(lo, "while parsing this or-pattern staring here");
+                err
+            })?;
             self.maybe_recover_unexpected_comma(pat.span, top_level)?;
             pats.push(pat);
         }
diff --git a/src/test/ui/or-patterns/while-parsing-this-or-pattern.rs b/src/test/ui/or-patterns/while-parsing-this-or-pattern.rs
new file mode 100644
index 00000000000..4a9fae1406a
--- /dev/null
+++ b/src/test/ui/or-patterns/while-parsing-this-or-pattern.rs
@@ -0,0 +1,9 @@
+// Test the parser for the "while parsing this or-pattern..." label here.
+
+fn main() {
+    match Some(42) {
+        Some(42) | .=. => {} //~ ERROR expected pattern, found `.`
+        //~^ while parsing this or-pattern staring here
+        //~| NOTE expected pattern
+    }
+}
diff --git a/src/test/ui/or-patterns/while-parsing-this-or-pattern.stderr b/src/test/ui/or-patterns/while-parsing-this-or-pattern.stderr
new file mode 100644
index 00000000000..21fece6c64f
--- /dev/null
+++ b/src/test/ui/or-patterns/while-parsing-this-or-pattern.stderr
@@ -0,0 +1,10 @@
+error: expected pattern, found `.`
+  --> $DIR/while-parsing-this-or-pattern.rs:5:20
+   |
+LL |         Some(42) | .=. => {}
+   |         --------   ^ expected pattern
+   |         |
+   |         while parsing this or-pattern staring here
+
+error: aborting due to previous error
+