diff options
Diffstat (limited to 'compiler/rustc_parse/src/parser/mod.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/mod.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index ed95a5661b1..74481e236f3 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -522,27 +522,27 @@ impl<'a> Parser<'a> { self.parse_ident_common(true) } + fn ident_or_err(&mut self) -> PResult<'a, (Ident, /* is_raw */ bool)> { + self.token.ident().ok_or_else(|| match self.prev_token.kind { + TokenKind::DocComment(..) => { + self.span_fatal_err(self.prev_token.span, Error::UselessDocComment) + } + _ => self.expected_ident_found(), + }) + } + fn parse_ident_common(&mut self, recover: bool) -> PResult<'a, Ident> { - match self.token.ident() { - Some((ident, is_raw)) => { - if !is_raw && ident.is_reserved() { - let mut err = self.expected_ident_found(); - if recover { - err.emit(); - } else { - return Err(err); - } - } - self.bump(); - Ok(ident) + let (ident, is_raw) = self.ident_or_err()?; + if !is_raw && ident.is_reserved() { + let mut err = self.expected_ident_found(); + if recover { + err.emit(); + } else { + return Err(err); } - _ => Err(match self.prev_token.kind { - TokenKind::DocComment(..) => { - self.span_fatal_err(self.prev_token.span, Error::UselessDocComment) - } - _ => self.expected_ident_found(), - }), } + self.bump(); + Ok(ident) } /// Checks if the next token is `tok`, and returns `true` if so. |
