From a9ef8592e47808539ffd9237c22ce5518aa7b188 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 24 Aug 2019 22:12:19 +0200 Subject: parser: bool -> TopLevel. --- src/libsyntax/parse/parser/pat.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/libsyntax/parse/parser') 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> { // 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 -- cgit 1.4.1-3-g733a5