@@ -3,12 +3,12 @@ use crate::errors::{
3
3
SuffixedLiteralInAttribute ,
4
4
} ;
5
5
use crate :: fluent_generated as fluent;
6
- use crate :: maybe_whole ;
6
+ use crate :: maybe_reparse_metavar_seq ;
7
7
8
- use super :: { AttrWrapper , Capturing , FnParseMode , ForceCollect , Parser , PathStyle } ;
8
+ use super :: { AttrWrapper , Capturing , FnParseMode , ForceCollect , ParseNtResult , Parser , PathStyle } ;
9
9
use rustc_ast as ast;
10
10
use rustc_ast:: attr;
11
- use rustc_ast:: token:: { self , Delimiter } ;
11
+ use rustc_ast:: token:: { self , Delimiter , NonterminalKind } ;
12
12
use rustc_errors:: { codes:: * , Diag , PResult } ;
13
13
use rustc_span:: { sym, BytePos , Span } ;
14
14
use thin_vec:: ThinVec ;
@@ -252,7 +252,15 @@ impl<'a> Parser<'a> {
252
252
/// PATH `=` UNSUFFIXED_LIT
253
253
/// The delimiters or `=` are still put into the resulting token stream.
254
254
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
+ }
256
264
257
265
let do_parse = |this : & mut Self | {
258
266
let path = this. parse_path ( PathStyle :: Mod ) ?;
@@ -362,18 +370,21 @@ impl<'a> Parser<'a> {
362
370
/// meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
363
371
/// ```
364
372
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 ) {
371
382
Some ( meta) => {
372
- self . bump ( ) ;
373
- return Ok ( meta) ;
383
+ * self = parser ;
384
+ Ok ( meta)
374
385
}
375
- None => self . unexpected ( ) ? ,
376
- }
386
+ None => self . unexpected_any ( ) ,
387
+ } ;
377
388
}
378
389
379
390
let lo = self . token . span ;
@@ -426,7 +437,8 @@ impl<'a> Parser<'a> {
426
437
} ) ) ;
427
438
}
428
439
429
- 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 } ) )
430
442
}
431
443
}
432
444
0 commit comments