Skip to content

Commit e6ab511

Browse files
committed
Auto merge of #43904 - topecongiro:libsyntax/parse-attr, r=petrochenkov
Eat open paren when parsing list in libsyntax/parse/attr.rs This PR adds a small refactoring: ```diff pub fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> { Ok(if self.eat(&token::Eq) { ast::MetaItemKind::NameValue(self.parse_unsuffixed_lit()?) - } else if self.token == token::OpenDelim(token::Paren) { + } else if self.eat(&token::OpenDelim(token::Paren)) { ast::MetaItemKind::List(self.parse_meta_seq()?) } else { - self.eat(&token::OpenDelim(token::Paren)); ast::MetaItemKind::Word }) } ``` in `parse_meta_item_kind()`, the parser calls `self.eat(&token::OpenDelim(token::Paren));` before returning `ast::MetaItemKind::Word` just to add `(` to expected token. It seems more natural to eat the paren when parsing `ast::MetaItemKind::List`.
2 parents 8016eea + 0bfe417 commit e6ab511

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/libsyntax/parse/attr.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,9 @@ impl<'a> Parser<'a> {
244244
pub fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> {
245245
Ok(if self.eat(&token::Eq) {
246246
ast::MetaItemKind::NameValue(self.parse_unsuffixed_lit()?)
247-
} else if self.token == token::OpenDelim(token::Paren) {
247+
} else if self.eat(&token::OpenDelim(token::Paren)) {
248248
ast::MetaItemKind::List(self.parse_meta_seq()?)
249249
} else {
250-
self.eat(&token::OpenDelim(token::Paren));
251250
ast::MetaItemKind::Word
252251
})
253252
}
@@ -277,9 +276,8 @@ impl<'a> Parser<'a> {
277276

278277
/// matches meta_seq = ( COMMASEP(meta_item_inner) )
279278
fn parse_meta_seq(&mut self) -> PResult<'a, Vec<ast::NestedMetaItem>> {
280-
self.parse_unspanned_seq(&token::OpenDelim(token::Paren),
281-
&token::CloseDelim(token::Paren),
282-
SeqSep::trailing_allowed(token::Comma),
283-
|p: &mut Parser<'a>| p.parse_meta_item_inner())
279+
self.parse_seq_to_end(&token::CloseDelim(token::Paren),
280+
SeqSep::trailing_allowed(token::Comma),
281+
|p: &mut Parser<'a>| p.parse_meta_item_inner())
284282
}
285283
}

0 commit comments

Comments
 (0)