@@ -4324,52 +4324,49 @@ impl<'a> Parser<'a> {
4324
4324
fn eat_macro_def ( & mut self , attrs : & [ Attribute ] , vis : & Visibility , lo : Span )
4325
4325
-> PResult < ' a , Option < P < Item > > > {
4326
4326
let token_lo = self . token . span ;
4327
- let ( ident, def) = match self . token . kind {
4328
- token:: Ident ( name, false ) if name == kw:: Macro => {
4329
- self . bump ( ) ;
4330
- let ident = self . parse_ident ( ) ?;
4331
- let tokens = if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
4332
- match self . parse_token_tree ( ) {
4333
- TokenTree :: Delimited ( _, _, tts) => tts,
4334
- _ => unreachable ! ( ) ,
4335
- }
4336
- } else if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
4337
- let args = self . parse_token_tree ( ) ;
4338
- let body = if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
4339
- self . parse_token_tree ( )
4340
- } else {
4341
- self . unexpected ( ) ?;
4342
- unreachable ! ( )
4343
- } ;
4344
- TokenStream :: new ( vec ! [
4345
- args. into( ) ,
4346
- TokenTree :: token( token:: FatArrow , token_lo. to( self . prev_span) ) . into( ) ,
4347
- body. into( ) ,
4348
- ] )
4327
+ let ( ident, def) = if self . eat_keyword ( kw:: Macro ) {
4328
+ let ident = self . parse_ident ( ) ?;
4329
+ let tokens = if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
4330
+ match self . parse_token_tree ( ) {
4331
+ TokenTree :: Delimited ( _, _, tts) => tts,
4332
+ _ => unreachable ! ( ) ,
4333
+ }
4334
+ } else if self . check ( & token:: OpenDelim ( token:: Paren ) ) {
4335
+ let args = self . parse_token_tree ( ) ;
4336
+ let body = if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
4337
+ self . parse_token_tree ( )
4349
4338
} else {
4350
4339
self . unexpected ( ) ?;
4351
4340
unreachable ! ( )
4352
4341
} ;
4342
+ TokenStream :: new ( vec ! [
4343
+ args. into( ) ,
4344
+ TokenTree :: token( token:: FatArrow , token_lo. to( self . prev_span) ) . into( ) ,
4345
+ body. into( ) ,
4346
+ ] )
4347
+ } else {
4348
+ self . unexpected ( ) ?;
4349
+ unreachable ! ( )
4350
+ } ;
4353
4351
4354
- ( ident, ast:: MacroDef { tokens : tokens. into ( ) , legacy : false } )
4355
- }
4356
- token:: Ident ( name, false ) if name == sym:: macro_rules &&
4357
- self . look_ahead ( 1 , |t| * t == token:: Not ) &&
4358
- self . look_ahead ( 2 , |t| t. is_ident ( ) ) => {
4359
- let prev_span = self . prev_span ;
4360
- self . complain_if_pub_macro ( & vis. node , prev_span) ;
4361
- self . bump ( ) ;
4362
- self . bump ( ) ;
4363
-
4364
- let ident = self . parse_ident ( ) ?;
4365
- let ( delim, tokens) = self . expect_delimited_token_tree ( ) ?;
4366
- if delim != MacDelimiter :: Brace && !self . eat ( & token:: Semi ) {
4367
- self . report_invalid_macro_expansion_item ( ) ;
4368
- }
4352
+ ( ident, ast:: MacroDef { tokens : tokens. into ( ) , legacy : false } )
4353
+ } else if self . check_keyword ( sym:: macro_rules) &&
4354
+ self . look_ahead ( 1 , |t| * t == token:: Not ) &&
4355
+ self . look_ahead ( 2 , |t| t. is_ident ( ) ) {
4356
+ let prev_span = self . prev_span ;
4357
+ self . complain_if_pub_macro ( & vis. node , prev_span) ;
4358
+ self . bump ( ) ;
4359
+ self . bump ( ) ;
4369
4360
4370
- ( ident, ast:: MacroDef { tokens, legacy : true } )
4361
+ let ident = self . parse_ident ( ) ?;
4362
+ let ( delim, tokens) = self . expect_delimited_token_tree ( ) ?;
4363
+ if delim != MacDelimiter :: Brace && !self . eat ( & token:: Semi ) {
4364
+ self . report_invalid_macro_expansion_item ( ) ;
4371
4365
}
4372
- _ => return Ok ( None ) ,
4366
+
4367
+ ( ident, ast:: MacroDef { tokens, legacy : true } )
4368
+ } else {
4369
+ return Ok ( None ) ;
4373
4370
} ;
4374
4371
4375
4372
let span = lo. to ( self . prev_span ) ;
@@ -4413,14 +4410,14 @@ impl<'a> Parser<'a> {
4413
4410
!self . is_existential_type_decl ( ) &&
4414
4411
!self . is_auto_trait_item ( ) &&
4415
4412
!self . is_async_fn ( ) {
4416
- let pth = self . parse_path ( PathStyle :: Expr ) ?;
4413
+ let path = self . parse_path ( PathStyle :: Expr ) ?;
4417
4414
4418
4415
if !self . eat ( & token:: Not ) {
4419
4416
let expr = if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
4420
- self . parse_struct_expr ( lo, pth , ThinVec :: new ( ) ) ?
4417
+ self . parse_struct_expr ( lo, path , ThinVec :: new ( ) ) ?
4421
4418
} else {
4422
4419
let hi = self . prev_span ;
4423
- self . mk_expr ( lo. to ( hi) , ExprKind :: Path ( None , pth ) , ThinVec :: new ( ) )
4420
+ self . mk_expr ( lo. to ( hi) , ExprKind :: Path ( None , path ) , ThinVec :: new ( ) )
4424
4421
} ;
4425
4422
4426
4423
let expr = self . with_res ( Restrictions :: STMT_EXPR , |this| {
@@ -4444,7 +4441,7 @@ impl<'a> Parser<'a> {
4444
4441
MacStmtStyle :: NoBraces
4445
4442
} ;
4446
4443
4447
- let mac = respan ( lo. to ( hi) , Mac_ { path : pth , tts, delim } ) ;
4444
+ let mac = respan ( lo. to ( hi) , Mac_ { path, tts, delim } ) ;
4448
4445
let node = if delim == MacDelimiter :: Brace ||
4449
4446
self . token == token:: Semi || self . token == token:: Eof {
4450
4447
StmtKind :: Mac ( P ( ( mac, style, attrs. into ( ) ) ) )
@@ -7561,15 +7558,15 @@ impl<'a> Parser<'a> {
7561
7558
let mac_lo = self . token . span ;
7562
7559
7563
7560
// item macro.
7564
- let pth = self . parse_path ( PathStyle :: Mod ) ?;
7561
+ let path = self . parse_path ( PathStyle :: Mod ) ?;
7565
7562
self . expect ( & token:: Not ) ?;
7566
7563
let ( delim, tts) = self . expect_delimited_token_tree ( ) ?;
7567
7564
if delim != MacDelimiter :: Brace && !self . eat ( & token:: Semi ) {
7568
7565
self . report_invalid_macro_expansion_item ( ) ;
7569
7566
}
7570
7567
7571
7568
let hi = self . prev_span ;
7572
- let mac = respan ( mac_lo. to ( hi) , Mac_ { path : pth , tts, delim } ) ;
7569
+ let mac = respan ( mac_lo. to ( hi) , Mac_ { path, tts, delim } ) ;
7573
7570
let item =
7574
7571
self . mk_item ( lo. to ( hi) , Ident :: invalid ( ) , ItemKind :: Mac ( mac) , visibility, attrs) ;
7575
7572
return Ok ( Some ( item) ) ;
@@ -7597,9 +7594,9 @@ impl<'a> Parser<'a> {
7597
7594
!( self . is_async_fn ( ) && self . token . span . rust_2015 ( ) ) {
7598
7595
let prev_span = self . prev_span ;
7599
7596
let lo = self . token . span ;
7600
- let pth = self . parse_path ( PathStyle :: Mod ) ?;
7597
+ let path = self . parse_path ( PathStyle :: Mod ) ?;
7601
7598
7602
- if pth . segments . len ( ) == 1 {
7599
+ if path . segments . len ( ) == 1 {
7603
7600
if !self . eat ( & token:: Not ) {
7604
7601
return Err ( self . missing_assoc_item_kind_err ( item_kind, prev_span) ) ;
7605
7602
}
@@ -7619,7 +7616,7 @@ impl<'a> Parser<'a> {
7619
7616
self . expect ( & token:: Semi ) ?;
7620
7617
}
7621
7618
7622
- Ok ( Some ( respan ( lo. to ( self . prev_span ) , Mac_ { path : pth , tts, delim } ) ) )
7619
+ Ok ( Some ( respan ( lo. to ( self . prev_span ) , Mac_ { path, tts, delim } ) ) )
7623
7620
} else {
7624
7621
Ok ( None )
7625
7622
}
0 commit comments