about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-08-18 15:28:14 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-08-24 21:31:54 +0200
commit5299d8a191246cf55c8ead7b8be68c8aeca78d35 (patch)
treea8294531d68f55d561e7c1cc347a4bf0204e82b6 /src/libsyntax/parse
parent5ade61a4f1515d4a18f38dacdbdb592bfd384a84 (diff)
downloadrust-5299d8a191246cf55c8ead7b8be68c8aeca78d35.tar.gz
rust-5299d8a191246cf55c8ead7b8be68c8aeca78d35.zip
parser: extract `ban_unexpected_or_or`.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser/pat.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs
index 8cfa6abbe62..4cda14907e4 100644
--- a/src/libsyntax/parse/parser/pat.rs
+++ b/src/libsyntax/parse/parser/pat.rs
@@ -31,14 +31,7 @@ impl<'a> Parser<'a> {
             pats.push(self.parse_top_level_pat()?);
 
             if self.token == token::OrOr {
-                self.struct_span_err(self.token.span, "unexpected token `||` after pattern")
-                    .span_suggestion(
-                        self.token.span,
-                        "use a single `|` to specify multiple patterns",
-                        "|".to_owned(),
-                        Applicability::MachineApplicable
-                    )
-                    .emit();
+                self.ban_unexpected_or_or();
                 self.bump();
             } else if self.eat(&token::BinOp(token::Or)) {
                 // This is a No-op. Continue the loop to parse the next
@@ -49,6 +42,17 @@ impl<'a> Parser<'a> {
         };
     }
 
+    fn ban_unexpected_or_or(&mut self) {
+        self.struct_span_err(self.token.span, "unexpected token `||` after pattern")
+            .span_suggestion(
+                self.token.span,
+                "use a single `|` to specify multiple patterns",
+                "|".to_owned(),
+                Applicability::MachineApplicable
+            )
+            .emit();
+    }
+
     /// A wrapper around `parse_pat` with some special error handling for the
     /// "top-level" patterns in a match arm, `for` loop, `let`, &c. (in contrast
     /// to subpatterns within such).
@@ -116,9 +120,7 @@ impl<'a> Parser<'a> {
         let mut pats = vec![first_pat];
 
         while self.eat(&token::BinOp(token::Or)) {
-            pats.push(self.parse_pat_with_range_pat(
-                true, expected
-            )?);
+            pats.push(self.parse_pat_with_range_pat(true, expected)?);
         }
 
         let or_pattern_span = lo.to(self.prev_span);