Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix recovery enabled on field name parsing
  • Loading branch information
jedel1043 committed Apr 22, 2021
commit b951e6c18c7b9548d43439b06d9d161e7c54333c
15 changes: 10 additions & 5 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,16 +832,20 @@ impl<'a> Parser<'a> {
}

fn parse_rename(&mut self) -> PResult<'a, Option<Ident>> {
if self.eat_keyword(kw::As) { self.parse_ident_or_underscore().map(Some) } else { Ok(None) }
if self.eat_keyword(kw::As) {
self.parse_ident_or_underscore(true).map(Some)
} else {
Ok(None)
}
}

fn parse_ident_or_underscore(&mut self) -> PResult<'a, Ident> {
fn parse_ident_or_underscore(&mut self, recover: bool) -> PResult<'a, Ident> {
match self.token.ident() {
Some((ident @ Ident { name: kw::Underscore, .. }, false)) => {
self.bump();
Ok(ident)
}
_ => self.parse_ident(),
_ => self.parse_ident_common(recover),
}
}

Expand Down Expand Up @@ -1056,7 +1060,8 @@ impl<'a> Parser<'a> {
&mut self,
m: Option<Mutability>,
) -> PResult<'a, (Ident, P<Ty>, Option<P<ast::Expr>>)> {
let id = if m.is_none() { self.parse_ident_or_underscore() } else { self.parse_ident() }?;
let id =
if m.is_none() { self.parse_ident_or_underscore(true) } else { self.parse_ident() }?;

// Parse the type of a `const` or `static mut?` item.
// That is, the `":" $ty` fragment.
Expand Down Expand Up @@ -1470,7 +1475,7 @@ impl<'a> Parser<'a> {
vis: Visibility,
attrs: Vec<Attribute>,
) -> PResult<'a, FieldDef> {
let name = self.parse_ident_or_underscore()?;
let name = self.parse_ident_or_underscore(false)?;
self.expect(&token::Colon)?;
if name.name == kw::Underscore {
self.parse_unnamed_field_type(lo, vis, attrs)
Expand Down