@@ -3,11 +3,12 @@ use crate::errors::{
3
3
SuffixedLiteralInAttribute ,
4
4
} ;
5
5
use crate :: fluent_generated as fluent;
6
+ use crate :: maybe_whole;
6
7
7
8
use super :: { AttrWrapper , Capturing , FnParseMode , ForceCollect , Parser , PathStyle } ;
8
9
use rustc_ast as ast;
9
10
use rustc_ast:: attr;
10
- use rustc_ast:: token:: { self , Delimiter , Nonterminal } ;
11
+ use rustc_ast:: token:: { self , Delimiter } ;
11
12
use rustc_errors:: { codes:: * , Diag , PResult } ;
12
13
use rustc_span:: { sym, BytePos , Span } ;
13
14
use thin_vec:: ThinVec ;
@@ -251,25 +252,15 @@ impl<'a> Parser<'a> {
251
252
/// PATH `=` UNSUFFIXED_LIT
252
253
/// The delimiters or `=` are still put into the resulting token stream.
253
254
pub fn parse_attr_item ( & mut self , capture_tokens : bool ) -> PResult < ' a , ast:: AttrItem > {
254
- let item = match & self . token . kind {
255
- token :: Interpolated ( nt ) => match & nt . 0 {
256
- Nonterminal :: NtMeta ( item ) => Some ( item . clone ( ) . into_inner ( ) ) ,
257
- _ => None ,
258
- } ,
259
- _ => None ,
255
+ maybe_whole ! ( self , NtMeta , |attr| attr . into_inner ( ) ) ;
256
+
257
+ let do_parse = | this : & mut Self | {
258
+ let path = this . parse_path ( PathStyle :: Mod ) ? ;
259
+ let args = this . parse_attr_args ( ) ? ;
260
+ Ok ( ast :: AttrItem { path , args , tokens : None } )
260
261
} ;
261
- Ok ( if let Some ( item) = item {
262
- self . bump ( ) ;
263
- item
264
- } else {
265
- let do_parse = |this : & mut Self | {
266
- let path = this. parse_path ( PathStyle :: Mod ) ?;
267
- let args = this. parse_attr_args ( ) ?;
268
- Ok ( ast:: AttrItem { path, args, tokens : None } )
269
- } ;
270
- // Attr items don't have attributes
271
- if capture_tokens { self . collect_tokens_no_attrs ( do_parse) } else { do_parse ( self ) } ?
272
- } )
262
+ // Attr items don't have attributes
263
+ if capture_tokens { self . collect_tokens_no_attrs ( do_parse) } else { do_parse ( self ) }
273
264
}
274
265
275
266
/// Parses attributes that appear after the opening of an item. These should
0 commit comments