@@ -4353,8 +4353,9 @@ impl<'a> Parser<'a> {
4353
4353
4354
4354
( ident, ast:: MacroDef { tokens : tokens. into ( ) , legacy : false } )
4355
4355
}
4356
- token:: Ident ( name, _) if name == sym:: macro_rules &&
4357
- self . look_ahead ( 1 , |t| * t == token:: Not ) => {
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 ( ) ) => {
4358
4359
let prev_span = self . prev_span ;
4359
4360
self . complain_if_pub_macro ( & vis. node , prev_span) ;
4360
4361
self . bump ( ) ;
@@ -4434,34 +4435,6 @@ impl<'a> Parser<'a> {
4434
4435
} ) ) ;
4435
4436
}
4436
4437
4437
- // it's a macro invocation
4438
- let id = match self . token . kind {
4439
- token:: OpenDelim ( _) => Ident :: invalid ( ) , // no special identifier
4440
- _ => self . parse_ident ( ) ?,
4441
- } ;
4442
-
4443
- // check that we're pointing at delimiters (need to check
4444
- // again after the `if`, because of `parse_ident`
4445
- // consuming more tokens).
4446
- match self . token . kind {
4447
- token:: OpenDelim ( _) => { }
4448
- _ => {
4449
- // we only expect an ident if we didn't parse one
4450
- // above.
4451
- let ident_str = if id. name == kw:: Invalid {
4452
- "identifier, "
4453
- } else {
4454
- ""
4455
- } ;
4456
- let tok_str = self . this_token_descr ( ) ;
4457
- let mut err = self . fatal ( & format ! ( "expected {}`(` or `{{`, found {}" ,
4458
- ident_str,
4459
- tok_str) ) ;
4460
- err. span_label ( self . token . span , format ! ( "expected {}`(` or `{{`" , ident_str) ) ;
4461
- return Err ( err)
4462
- } ,
4463
- }
4464
-
4465
4438
let ( delim, tts) = self . expect_delimited_token_tree ( ) ?;
4466
4439
let hi = self . prev_span ;
4467
4440
@@ -4471,59 +4444,38 @@ impl<'a> Parser<'a> {
4471
4444
MacStmtStyle :: NoBraces
4472
4445
} ;
4473
4446
4474
- if id. name == kw:: Invalid {
4475
- let mac = respan ( lo. to ( hi) , Mac_ { path : pth, tts, delim } ) ;
4476
- let node = if delim == MacDelimiter :: Brace ||
4477
- self . token == token:: Semi || self . token == token:: Eof {
4478
- StmtKind :: Mac ( P ( ( mac, style, attrs. into ( ) ) ) )
4479
- }
4480
- // We used to incorrectly stop parsing macro-expanded statements here.
4481
- // If the next token will be an error anyway but could have parsed with the
4482
- // earlier behavior, stop parsing here and emit a warning to avoid breakage.
4483
- else if macro_legacy_warnings &&
4484
- self . token . can_begin_expr ( ) &&
4485
- match self . token . kind {
4486
- // These can continue an expression, so we can't stop parsing and warn.
4487
- token:: OpenDelim ( token:: Paren ) | token:: OpenDelim ( token:: Bracket ) |
4488
- token:: BinOp ( token:: Minus ) | token:: BinOp ( token:: Star ) |
4489
- token:: BinOp ( token:: And ) | token:: BinOp ( token:: Or ) |
4490
- token:: AndAnd | token:: OrOr |
4491
- token:: DotDot | token:: DotDotDot | token:: DotDotEq => false ,
4492
- _ => true ,
4493
- } {
4494
- self . warn_missing_semicolon ( ) ;
4495
- StmtKind :: Mac ( P ( ( mac, style, attrs. into ( ) ) ) )
4496
- } else {
4497
- let e = self . mk_expr ( mac. span , ExprKind :: Mac ( mac) , ThinVec :: new ( ) ) ;
4498
- let e = self . maybe_recover_from_bad_qpath ( e, true ) ?;
4499
- let e = self . parse_dot_or_call_expr_with ( e, lo, attrs. into ( ) ) ?;
4500
- let e = self . parse_assoc_expr_with ( 0 , LhsExpr :: AlreadyParsed ( e) ) ?;
4501
- StmtKind :: Expr ( e)
4502
- } ;
4503
- Stmt {
4504
- id : ast:: DUMMY_NODE_ID ,
4505
- span : lo. to ( hi) ,
4506
- node,
4507
- }
4447
+ let mac = respan ( lo. to ( hi) , Mac_ { path : pth, tts, delim } ) ;
4448
+ let node = if delim == MacDelimiter :: Brace ||
4449
+ self . token == token:: Semi || self . token == token:: Eof {
4450
+ StmtKind :: Mac ( P ( ( mac, style, attrs. into ( ) ) ) )
4451
+ }
4452
+ // We used to incorrectly stop parsing macro-expanded statements here.
4453
+ // If the next token will be an error anyway but could have parsed with the
4454
+ // earlier behavior, stop parsing here and emit a warning to avoid breakage.
4455
+ else if macro_legacy_warnings &&
4456
+ self . token . can_begin_expr ( ) &&
4457
+ match self . token . kind {
4458
+ // These can continue an expression, so we can't stop parsing and warn.
4459
+ token:: OpenDelim ( token:: Paren ) | token:: OpenDelim ( token:: Bracket ) |
4460
+ token:: BinOp ( token:: Minus ) | token:: BinOp ( token:: Star ) |
4461
+ token:: BinOp ( token:: And ) | token:: BinOp ( token:: Or ) |
4462
+ token:: AndAnd | token:: OrOr |
4463
+ token:: DotDot | token:: DotDotDot | token:: DotDotEq => false ,
4464
+ _ => true ,
4465
+ } {
4466
+ self . warn_missing_semicolon ( ) ;
4467
+ StmtKind :: Mac ( P ( ( mac, style, attrs. into ( ) ) ) )
4508
4468
} else {
4509
- // if it has a special ident, it's definitely an item
4510
- //
4511
- // Require a semicolon or braces.
4512
- if style != MacStmtStyle :: Braces && !self . eat ( & token:: Semi ) {
4513
- self . report_invalid_macro_expansion_item ( ) ;
4514
- }
4515
- let span = lo. to ( hi) ;
4516
- Stmt {
4517
- id : ast:: DUMMY_NODE_ID ,
4518
- span,
4519
- node : StmtKind :: Item ( {
4520
- self . mk_item (
4521
- span, id /*id is good here*/ ,
4522
- ItemKind :: Mac ( respan ( span, Mac_ { path : pth, tts, delim } ) ) ,
4523
- respan ( lo, VisibilityKind :: Inherited ) ,
4524
- attrs)
4525
- } ) ,
4526
- }
4469
+ let e = self . mk_expr ( mac. span , ExprKind :: Mac ( mac) , ThinVec :: new ( ) ) ;
4470
+ let e = self . maybe_recover_from_bad_qpath ( e, true ) ?;
4471
+ let e = self . parse_dot_or_call_expr_with ( e, lo, attrs. into ( ) ) ?;
4472
+ let e = self . parse_assoc_expr_with ( 0 , LhsExpr :: AlreadyParsed ( e) ) ?;
4473
+ StmtKind :: Expr ( e)
4474
+ } ;
4475
+ Stmt {
4476
+ id : ast:: DUMMY_NODE_ID ,
4477
+ span : lo. to ( hi) ,
4478
+ node,
4527
4479
}
4528
4480
} else {
4529
4481
// FIXME: Bad copy of attrs
@@ -7611,24 +7563,15 @@ impl<'a> Parser<'a> {
7611
7563
// item macro.
7612
7564
let pth = self . parse_path ( PathStyle :: Mod ) ?;
7613
7565
self . expect ( & token:: Not ) ?;
7614
-
7615
- // a 'special' identifier (like what `macro_rules!` uses)
7616
- // is optional. We should eventually unify invoc syntax
7617
- // and remove this.
7618
- let id = if self . token . is_ident ( ) {
7619
- self . parse_ident ( ) ?
7620
- } else {
7621
- Ident :: invalid ( ) // no special identifier
7622
- } ;
7623
- // eat a matched-delimiter token tree:
7624
7566
let ( delim, tts) = self . expect_delimited_token_tree ( ) ?;
7625
7567
if delim != MacDelimiter :: Brace && !self . eat ( & token:: Semi ) {
7626
7568
self . report_invalid_macro_expansion_item ( ) ;
7627
7569
}
7628
7570
7629
7571
let hi = self . prev_span ;
7630
7572
let mac = respan ( mac_lo. to ( hi) , Mac_ { path : pth, tts, delim } ) ;
7631
- let item = self . mk_item ( lo. to ( hi) , id, ItemKind :: Mac ( mac) , visibility, attrs) ;
7573
+ let item =
7574
+ self . mk_item ( lo. to ( hi) , Ident :: invalid ( ) , ItemKind :: Mac ( mac) , visibility, attrs) ;
7632
7575
return Ok ( Some ( item) ) ;
7633
7576
}
7634
7577
0 commit comments