about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-08-24 22:12:19 +0200
committerMazdak Farrokhzad <twingoow@gmail.com>2019-08-24 22:48:23 +0200
commita9ef8592e47808539ffd9237c22ce5518aa7b188 (patch)
tree5bd42574a9a7c4ecfd49121aabb8f73d339ba947 /src/libsyntax/parse
parentb2966e651de3bf83ab9c712a1afaeba84162cab1 (diff)
downloadrust-a9ef8592e47808539ffd9237c22ce5518aa7b188.tar.gz
rust-a9ef8592e47808539ffd9237c22ce5518aa7b188.zip
parser: bool -> TopLevel.
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser/pat.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsyntax/parse/parser/pat.rs b/src/libsyntax/parse/parser/pat.rs
index 3d89ec56ffa..c168d033781 100644
--- a/src/libsyntax/parse/parser/pat.rs
+++ b/src/libsyntax/parse/parser/pat.rs
@@ -18,6 +18,10 @@ type Expected = Option<&'static str>;
 #[derive(PartialEq)]
 pub enum GateOr { Yes, No }
 
+/// Whether or not this is the top level pattern context.
+#[derive(PartialEq, Copy, Clone)]
+enum TopLevel { Yes, No }
+
 impl<'a> Parser<'a> {
     /// Parses a pattern.
     ///
@@ -46,7 +50,7 @@ impl<'a> Parser<'a> {
             self.sess.gated_spans.or_patterns.borrow_mut().push(self.prev_span);
         }
 
-        self.parse_pat_with_or(None, gate_or, true)
+        self.parse_pat_with_or(None, gate_or, TopLevel::Yes)
     }
 
     /// Parses a pattern, that may be a or-pattern (e.g. `Foo | Bar` in `Some(Foo | Bar)`).
@@ -55,7 +59,7 @@ impl<'a> Parser<'a> {
         &mut self,
         expected: Expected,
         gate_or: GateOr,
-        top_level: bool
+        top_level: TopLevel,
     ) -> PResult<'a, P<Pat>> {
         // Parse the first pattern.
         let first_pat = self.parse_pat(expected)?;
@@ -112,8 +116,8 @@ impl<'a> Parser<'a> {
 
     /// Some special error handling for the "top-level" patterns in a match arm,
     /// `for` loop, `let`, &c. (in contrast to subpatterns within such).
-    fn maybe_recover_unexpected_comma(&mut self, lo: Span, top_level: bool) -> PResult<'a, ()> {
-        if !top_level || self.token != token::Comma {
+    fn maybe_recover_unexpected_comma(&mut self, lo: Span, top_level: TopLevel) -> PResult<'a, ()> {
+        if top_level == TopLevel::No || self.token != token::Comma {
             return Ok(());
         }
 
@@ -175,7 +179,7 @@ impl<'a> Parser<'a> {
             self.bump();
         }
 
-        self.parse_pat_with_or(expected, GateOr::Yes, false)
+        self.parse_pat_with_or(expected, GateOr::Yes, TopLevel::No)
     }
 
     /// Parses a pattern, with a setting whether modern range patterns (e.g., `a..=b`, `a..b` are