@@ -3,12 +3,12 @@ use crate::errors::{
33 SuffixedLiteralInAttribute ,
44} ;
55use crate :: fluent_generated as fluent;
6- use crate :: maybe_whole ;
6+ use crate :: maybe_reparse_metavar_seq ;
77
8- use super :: { AttrWrapper , Capturing , FnParseMode , ForceCollect , Parser , PathStyle } ;
8+ use super :: { AttrWrapper , Capturing , FnParseMode , ForceCollect , ParseNtResult , Parser , PathStyle } ;
99use rustc_ast as ast;
1010use rustc_ast:: attr;
11- use rustc_ast:: token:: { self , Delimiter } ;
11+ use rustc_ast:: token:: { self , Delimiter , NonterminalKind } ;
1212use rustc_errors:: { codes:: * , Diag , PResult } ;
1313use rustc_span:: { sym, BytePos , Span } ;
1414use thin_vec:: ThinVec ;
@@ -252,7 +252,15 @@ impl<'a> Parser<'a> {
252252 /// PATH `=` UNSUFFIXED_LIT
253253 /// The delimiters or `=` are still put into the resulting token stream.
254254 pub fn parse_attr_item ( & mut self , capture_tokens : bool ) -> PResult < ' a , ast:: AttrItem > {
255- maybe_whole ! ( self , NtMeta , |attr| attr. into_inner( ) ) ;
255+ if let Some ( item) = maybe_reparse_metavar_seq ! (
256+ self ,
257+ NonterminalKind :: Meta ,
258+ NonterminalKind :: Meta ,
259+ ParseNtResult :: Meta ( item) ,
260+ item
261+ ) {
262+ return Ok ( item. into_inner ( ) ) ;
263+ }
256264
257265 let do_parse = |this : & mut Self | {
258266 let path = this. parse_path ( PathStyle :: Mod ) ?;
@@ -362,21 +370,21 @@ impl<'a> Parser<'a> {
362370 /// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
363371 /// ```
364372 pub fn parse_meta_item ( & mut self ) -> PResult < ' a , ast:: MetaItem > {
365- // We can't use `maybe_whole` here because it would bump in the `None`
366- // case, which we don't want.
367- if let token:: Interpolated ( nt) = & self . token . kind
368- && let token:: NtMeta ( attr_item) = & nt. 0
369- {
370- match attr_item. meta ( attr_item. path . span ) {
373+ let mut parser = self . clone ( ) ; // njn: ugh
374+ if let Some ( attr_item) = maybe_reparse_metavar_seq ! (
375+ parser,
376+ NonterminalKind :: Meta ,
377+ NonterminalKind :: Meta ,
378+ ParseNtResult :: Meta ( attr_item) ,
379+ attr_item
380+ ) {
381+ return match attr_item. meta ( attr_item. path . span ) {
371382 Some ( meta) => {
372- self . bump ( ) ;
373- return Ok ( meta) ;
383+ * self = parser ;
384+ Ok ( meta)
374385 }
375- None => self . unexpected ( ) ?,
376- }
377- }
378- if let token:: OpenDelim ( Delimiter :: Invisible ( _) ) = & self . token . kind {
379- panic ! ( "njn: invis-delim?" ) ;
386+ None => self . unexpected_any ( ) ,
387+ } ;
380388 }
381389
382390 let lo = self . token . span ;
@@ -429,7 +437,8 @@ impl<'a> Parser<'a> {
429437 } ) ) ;
430438 }
431439
432- Err ( self . dcx ( ) . create_err ( InvalidMetaItem { span : token. span , token } ) )
440+ let descr = super :: token_descr ( & token) ;
441+ Err ( self . dcx ( ) . create_err ( InvalidMetaItem { span : token. span , descr } ) )
433442 }
434443}
435444
0 commit comments