@@ -86,7 +86,7 @@ impl<'a> Parser<'a> {
8686 let vis = self . parse_visibility ( FollowedByType :: No ) ?;
8787
8888 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) ) ) ) ;
9090 }
9191
9292 // FAILURE TO PARSE ITEM
@@ -942,9 +942,7 @@ impl<'a> Parser<'a> {
942942 }
943943 self . unexpected ( ) ?
944944 } ;
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) ) )
948946 }
949947
950948 /// Parses a static item from a foreign module.
@@ -1364,7 +1362,7 @@ impl<'a> Parser<'a> {
13641362 }
13651363
13661364 /// 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 {
13681366 self . check_keyword ( sym:: macro_rules)
13691367 && self . look_ahead ( 1 , |t| * t == token:: Not )
13701368 && self . look_ahead ( 2 , |t| t. is_ident ( ) )
@@ -1385,22 +1383,6 @@ impl<'a> Parser<'a> {
13851383 Ok ( ( ident, ItemKind :: MacroDef ( ast:: MacroDef { body, legacy : true } ) ) )
13861384 }
13871385
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-
14041386 fn complain_if_pub_macro ( & self , vis : & VisibilityKind , sp : Span ) {
14051387 match * vis {
14061388 VisibilityKind :: Inherited => { }
@@ -1496,15 +1478,16 @@ impl<'a> Parser<'a> {
14961478 Ok ( true )
14971479 }
14981480
1499- fn mk_item (
1481+ fn mk_item < K > (
15001482 & self ,
1501- span : Span ,
1483+ lo : Span ,
15021484 ident : Ident ,
1503- kind : ItemKind ,
1485+ kind : K ,
15041486 vis : Visibility ,
15051487 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 }
15081491 }
15091492}
15101493
0 commit comments