diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-05-19 16:07:55 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-05-19 16:53:23 +1000 |
| commit | 7b6c5c76a5b4b1a7676f7792c92939c4a7e85f5b (patch) | |
| tree | 5c2d7324657c3f24c376cb282e0a3302498295e1 /compiler/rustc_parse/src | |
| parent | d4347ed6786d2f37218af1a4c112bf1d66500c02 (diff) | |
| download | rust-7b6c5c76a5b4b1a7676f7792c92939c4a7e85f5b.tar.gz rust-7b6c5c76a5b4b1a7676f7792c92939c4a7e85f5b.zip | |
Move condition out of `maybe_recover_unexpected_comma`.
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/pat.rs | 8 |
2 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index dc02a22b769..cbbaaa1ae37 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1,7 +1,7 @@ use super::pat::Expected; use super::{ - BlockMode, CommaRecoveryMode, Parser, PathStyle, RecoverComma, Restrictions, SemiColonMode, - SeqSep, TokenExpectType, TokenType, + BlockMode, CommaRecoveryMode, Parser, PathStyle, Restrictions, SemiColonMode, SeqSep, + TokenExpectType, TokenType, }; use crate::lexer::UnmatchedBrace; @@ -2580,10 +2580,9 @@ impl<'a> Parser<'a> { crate fn maybe_recover_unexpected_comma( &mut self, lo: Span, - rc: RecoverComma, rt: CommaRecoveryMode, ) -> PResult<'a, ()> { - if rc == RecoverComma::No || self.token != token::Comma { + if self.token != token::Comma { return Ok(()); } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index aec3f269956..2ad3f3ec19d 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -101,7 +101,9 @@ impl<'a> Parser<'a> { // Parse the first pattern (`p_0`). let mut first_pat = self.parse_pat_no_top_alt(expected)?; - self.maybe_recover_unexpected_comma(first_pat.span, rc, rt)?; + if rc == RecoverComma::Yes { + self.maybe_recover_unexpected_comma(first_pat.span, rt)?; + } // If the next token is not a `|`, // this is not an or-pattern and we should exit here. @@ -141,7 +143,9 @@ impl<'a> Parser<'a> { err.span_label(lo, WHILE_PARSING_OR_MSG); err })?; - self.maybe_recover_unexpected_comma(pat.span, rc, rt)?; + if rc == RecoverComma::Yes { + self.maybe_recover_unexpected_comma(pat.span, rt)?; + } pats.push(pat); } let or_pattern_span = lo.to(self.prev_token.span); |
