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} ;
24use rustc_errors:: codes:: * ;
35use rustc_errors:: { Diag , PResult } ;
46use rustc_span:: { BytePos , Span } ;
@@ -9,7 +11,7 @@ use super::{
911 AttrWrapper , Capturing , FnParseMode , ForceCollect , Parser , ParserRange , PathStyle , Trailing ,
1012 UsePreAttrPos ,
1113} ;
12- use crate :: { errors, exp, fluent_generated as fluent, maybe_whole } ;
14+ use crate :: { errors, exp, fluent_generated as fluent} ;
1315
1416// Public for rustfmt usage
1517#[ derive( Debug ) ]
@@ -269,7 +271,12 @@ impl<'a> Parser<'a> {
269271 /// PATH `=` UNSUFFIXED_LIT
270272 /// The delimiters or `=` are still put into the resulting token stream.
271273 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+ }
273280
274281 // Attr items don't have attributes.
275282 self . collect_tokens ( None , AttrWrapper :: empty ( ) , force_collect, |this, _empty_attrs| {
@@ -396,18 +403,17 @@ impl<'a> Parser<'a> {
396403 & mut self ,
397404 unsafe_allowed : AllowLeadingUnsafe ,
398405 ) -> 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+ } ;
411417 }
412418
413419 let lo = self . token . span ;
@@ -464,7 +470,7 @@ impl<'a> Parser<'a> {
464470
465471 let mut err = errors:: InvalidMetaItem {
466472 span : self . token . span ,
467- token : self . token . clone ( ) ,
473+ descr : super :: token_descr ( & self . token ) ,
468474 quote_ident_sugg : None ,
469475 } ;
470476
0 commit comments