@@ -86,7 +86,7 @@ impl<'a> Parser<'a> {
86
86
let vis = self . parse_visibility ( FollowedByType :: No ) ?;
87
87
88
88
if let Some ( ( ident, kind) ) = self . parse_item_kind ( & mut attrs, macros_allowed, lo, & vis) ? {
89
- return Ok ( Some ( self . mk_item ( lo. to ( self . prev_span ) , ident, kind, vis, attrs) ) ) ;
89
+ return Ok ( Some ( P ( self . mk_item ( lo, ident, kind, vis, attrs) ) ) ) ;
90
90
}
91
91
92
92
// FAILURE TO PARSE ITEM
@@ -942,9 +942,7 @@ impl<'a> Parser<'a> {
942
942
}
943
943
self . unexpected ( ) ?
944
944
} ;
945
-
946
- let span = lo. to ( self . prev_span ) ;
947
- Ok ( P ( ast:: ForeignItem { ident, attrs, kind, id : DUMMY_NODE_ID , span, vis, tokens : None } ) )
945
+ Ok ( P ( self . mk_item ( lo, ident, kind, vis, attrs) ) )
948
946
}
949
947
950
948
/// Parses a static item from a foreign module.
@@ -1364,7 +1362,7 @@ impl<'a> Parser<'a> {
1364
1362
}
1365
1363
1366
1364
/// Is this unambiguously the start of a `macro_rules! foo` item defnition?
1367
- fn is_macro_rules_item ( & mut self ) -> bool {
1365
+ pub ( super ) fn is_macro_rules_item ( & mut self ) -> bool {
1368
1366
self . check_keyword ( sym:: macro_rules)
1369
1367
&& self . look_ahead ( 1 , |t| * t == token:: Not )
1370
1368
&& self . look_ahead ( 2 , |t| t. is_ident ( ) )
@@ -1385,22 +1383,6 @@ impl<'a> Parser<'a> {
1385
1383
Ok ( ( ident, ItemKind :: MacroDef ( ast:: MacroDef { body, legacy : true } ) ) )
1386
1384
}
1387
1385
1388
- pub ( super ) fn eat_macro_def (
1389
- & mut self ,
1390
- attrs : & [ Attribute ] ,
1391
- vis : & Visibility ,
1392
- lo : Span ,
1393
- ) -> PResult < ' a , Option < P < Item > > > {
1394
- let ( ident, kind) = if self . eat_keyword ( kw:: Macro ) {
1395
- self . parse_item_decl_macro ( lo) ?
1396
- } else if self . is_macro_rules_item ( ) {
1397
- self . parse_item_macro_rules ( vis) ?
1398
- } else {
1399
- return Ok ( None ) ;
1400
- } ;
1401
- Ok ( Some ( self . mk_item ( lo. to ( self . prev_span ) , ident, kind, vis. clone ( ) , attrs. to_vec ( ) ) ) )
1402
- }
1403
-
1404
1386
fn complain_if_pub_macro ( & self , vis : & VisibilityKind , sp : Span ) {
1405
1387
match * vis {
1406
1388
VisibilityKind :: Inherited => { }
@@ -1496,15 +1478,16 @@ impl<'a> Parser<'a> {
1496
1478
Ok ( true )
1497
1479
}
1498
1480
1499
- fn mk_item (
1481
+ fn mk_item < K > (
1500
1482
& self ,
1501
- span : Span ,
1483
+ lo : Span ,
1502
1484
ident : Ident ,
1503
- kind : ItemKind ,
1485
+ kind : K ,
1504
1486
vis : Visibility ,
1505
1487
attrs : Vec < Attribute > ,
1506
- ) -> P < Item > {
1507
- P ( Item { ident, attrs, id : DUMMY_NODE_ID , kind, vis, span, tokens : None } )
1488
+ ) -> Item < K > {
1489
+ let span = lo. to ( self . prev_span ) ;
1490
+ Item { ident, attrs, id : DUMMY_NODE_ID , kind, vis, span, tokens : None }
1508
1491
}
1509
1492
}
1510
1493
0 commit comments