@@ -98,7 +98,10 @@ impl<'a> Parser<'a> {
9898
9999 if self . is_fn_front_matter ( ) {
100100 // FUNCTION ITEM
101- return self . parse_item_fn ( lo, vis, attrs) ;
101+ let ( ident, sig, generics, body) =
102+ self . parse_fn ( & mut false , & mut attrs, & ParamCfg :: FREE ) ?;
103+ let kind = ItemKind :: Fn ( sig, generics, body) ;
104+ return self . mk_item_with_info ( attrs, lo, vis, ( ident, kind, None ) ) ;
102105 }
103106
104107 if self . eat_keyword ( kw:: Extern ) {
@@ -741,7 +744,9 @@ impl<'a> Parser<'a> {
741744 let ( name, kind, generics) = if self . eat_keyword ( kw:: Type ) {
742745 self . parse_assoc_ty ( ) ?
743746 } else if self . is_fn_front_matter ( ) {
744- self . parse_assoc_fn ( at_end, & mut attrs, is_name_required) ?
747+ let cfg = ParamCfg { is_name_required } ;
748+ let ( ident, sig, generics, body) = self . parse_fn ( at_end, & mut attrs, & cfg) ?;
749+ ( ident, AssocItemKind :: Fn ( sig, body) , generics)
745750 } else if let Some ( mac) = self . parse_assoc_macro_invoc ( "associated" , Some ( & vis) , at_end) ? {
746751 ( Ident :: invalid ( ) , AssocItemKind :: Macro ( mac) , Generics :: default ( ) )
747752 } else {
@@ -968,7 +973,7 @@ impl<'a> Parser<'a> {
968973 pub fn parse_foreign_item ( & mut self ) -> PResult < ' a , P < ForeignItem > > {
969974 maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
970975
971- let attrs = self . parse_outer_attributes ( ) ?;
976+ let mut attrs = self . parse_outer_attributes ( ) ?;
972977 let lo = self . token . span ;
973978 let vis = self . parse_visibility ( FollowedByType :: No ) ?;
974979
@@ -977,7 +982,19 @@ impl<'a> Parser<'a> {
977982 self . parse_item_foreign_type ( vis, lo, attrs)
978983 } else if self . is_fn_front_matter ( ) {
979984 // FOREIGN FUNCTION ITEM
980- self . parse_item_foreign_fn ( vis, lo, attrs)
985+ let ( ident, sig, generics, body) =
986+ self . parse_fn ( & mut false , & mut attrs, & ParamCfg :: FREE ) ?;
987+ let kind = ForeignItemKind :: Fn ( sig, generics, body) ;
988+ let span = lo. to ( self . prev_span ) ;
989+ Ok ( P ( ast:: ForeignItem {
990+ ident,
991+ attrs,
992+ kind,
993+ id : DUMMY_NODE_ID ,
994+ span,
995+ vis,
996+ tokens : None ,
997+ } ) )
981998 } else if self . is_static_global ( ) {
982999 // FOREIGN STATIC ITEM
9831000 self . bump ( ) ; // `static`
@@ -1603,44 +1620,6 @@ impl ParamCfg {
16031620
16041621/// Parsing of functions and methods.
16051622impl < ' a > Parser < ' a > {
1606- /// Parses an item-position function declaration.
1607- fn parse_item_fn (
1608- & mut self ,
1609- lo : Span ,
1610- vis : Visibility ,
1611- mut attrs : Vec < Attribute > ,
1612- ) -> PResult < ' a , Option < P < Item > > > {
1613- let ( ident, sig, generics, body) =
1614- self . parse_fn ( & mut false , & mut attrs, & ParamCfg :: FREE ) ?;
1615- let kind = ItemKind :: Fn ( sig, generics, body) ;
1616- self . mk_item_with_info ( attrs, lo, vis, ( ident, kind, None ) )
1617- }
1618-
1619- /// Parses a function declaration from a foreign module.
1620- fn parse_item_foreign_fn (
1621- & mut self ,
1622- vis : ast:: Visibility ,
1623- lo : Span ,
1624- mut attrs : Vec < Attribute > ,
1625- ) -> PResult < ' a , P < ForeignItem > > {
1626- let ( ident, sig, generics, body) =
1627- self . parse_fn ( & mut false , & mut attrs, & ParamCfg :: FREE ) ?;
1628- let kind = ForeignItemKind :: Fn ( sig, generics, body) ;
1629- let span = lo. to ( self . prev_span ) ;
1630- Ok ( P ( ast:: ForeignItem { ident, attrs, kind, id : DUMMY_NODE_ID , span, vis, tokens : None } ) )
1631- }
1632-
1633- fn parse_assoc_fn (
1634- & mut self ,
1635- at_end : & mut bool ,
1636- attrs : & mut Vec < Attribute > ,
1637- is_name_required : fn ( & token:: Token ) -> bool ,
1638- ) -> PResult < ' a , ( Ident , AssocItemKind , Generics ) > {
1639- let cfg = ParamCfg { is_name_required } ;
1640- let ( ident, sig, generics, body) = self . parse_fn ( at_end, attrs, & cfg) ?;
1641- Ok ( ( ident, AssocItemKind :: Fn ( sig, body) , generics) )
1642- }
1643-
16441623 /// Parse a function starting from the front matter (`const ...`) to the body `{ ... }` or `;`.
16451624 fn parse_fn (
16461625 & mut self ,
0 commit comments