1
- use rustc_ast::{self as ast, Attribute, attr, token};
1
+ use rustc_ast as ast;
2
+ use rustc_ast::token::{self, MetaVarKind};
3
+ use rustc_ast::{Attribute, attr};
2
4
use rustc_errors::codes::*;
3
5
use rustc_errors::{Diag, PResult};
4
6
use rustc_span::{BytePos, Span};
@@ -9,7 +11,7 @@ use super::{
9
11
AttrWrapper, Capturing, FnParseMode, ForceCollect, Parser, ParserRange, PathStyle, Trailing,
10
12
UsePreAttrPos,
11
13
};
12
- use crate::{errors, exp, fluent_generated as fluent, maybe_whole };
14
+ use crate::{errors, exp, fluent_generated as fluent};
13
15
14
16
// Public for rustfmt usage
15
17
#[derive(Debug)]
@@ -269,7 +271,12 @@ impl<'a> Parser<'a> {
269
271
/// PATH `=` UNSUFFIXED_LIT
270
272
/// The delimiters or `=` are still put into the resulting token stream.
271
273
pub fn parse_attr_item(&mut self, force_collect: ForceCollect) -> PResult<'a, ast::AttrItem> {
272
- maybe_whole!(self, NtMeta, |attr| attr.into_inner());
274
+ if let Some(item) = self.eat_metavar_seq_with_matcher(
275
+ |mv_kind| matches!(mv_kind, MetaVarKind::Meta { .. }),
276
+ |this| this.parse_attr_item(force_collect),
277
+ ) {
278
+ return Ok(item);
279
+ }
273
280
274
281
// Attr items don't have attributes.
275
282
self.collect_tokens(None, AttrWrapper::empty(), force_collect, |this, _empty_attrs| {
@@ -396,18 +403,17 @@ impl<'a> Parser<'a> {
396
403
&mut self,
397
404
unsafe_allowed: AllowLeadingUnsafe,
398
405
) -> PResult<'a, ast::MetaItem> {
399
- // We can't use `maybe_whole` here because it would bump in the `None`
400
- // case, which we don't want.
401
- if let token::Interpolated(nt) = &self.token.kind
402
- && let token::NtMeta(attr_item) = &**nt
403
- {
404
- match attr_item.meta(attr_item.path.span) {
405
- Some(meta) => {
406
- self.bump();
407
- return Ok(meta);
408
- }
409
- None => self.unexpected()?,
410
- }
406
+ if let Some(MetaVarKind::Meta { has_meta_form }) = self.token.is_metavar_seq() {
407
+ return if has_meta_form {
408
+ let attr_item = self
409
+ .eat_metavar_seq(MetaVarKind::Meta { has_meta_form: true }, |this| {
410
+ this.parse_attr_item(ForceCollect::No)
411
+ })
412
+ .unwrap();
413
+ Ok(attr_item.meta(attr_item.path.span).unwrap())
414
+ } else {
415
+ self.unexpected_any()
416
+ };
411
417
}
412
418
413
419
let lo = self.token.span;
@@ -464,7 +470,7 @@ impl<'a> Parser<'a> {
464
470
465
471
let mut err = errors::InvalidMetaItem {
466
472
span: self.token.span,
467
- token: self.token.clone( ),
473
+ descr: super::token_descr(& self.token),
468
474
quote_ident_sugg: None,
469
475
};
470
476
0 commit comments