@@ -98,7 +98,10 @@ impl<'a> Parser<'a> {
98
98
99
99
if self . is_fn_front_matter ( ) {
100
100
// 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 ) ) ;
102
105
}
103
106
104
107
if self . eat_keyword ( kw:: Extern ) {
@@ -741,7 +744,9 @@ impl<'a> Parser<'a> {
741
744
let ( name, kind, generics) = if self . eat_keyword ( kw:: Type ) {
742
745
self . parse_assoc_ty ( ) ?
743
746
} 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)
745
750
} else if let Some ( mac) = self . parse_assoc_macro_invoc ( "associated" , Some ( & vis) , at_end) ? {
746
751
( Ident :: invalid ( ) , AssocItemKind :: Macro ( mac) , Generics :: default ( ) )
747
752
} else {
@@ -968,7 +973,7 @@ impl<'a> Parser<'a> {
968
973
pub fn parse_foreign_item ( & mut self ) -> PResult < ' a , P < ForeignItem > > {
969
974
maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
970
975
971
- let attrs = self . parse_outer_attributes ( ) ?;
976
+ let mut attrs = self . parse_outer_attributes ( ) ?;
972
977
let lo = self . token . span ;
973
978
let vis = self . parse_visibility ( FollowedByType :: No ) ?;
974
979
@@ -977,7 +982,19 @@ impl<'a> Parser<'a> {
977
982
self . parse_item_foreign_type ( vis, lo, attrs)
978
983
} else if self . is_fn_front_matter ( ) {
979
984
// 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
+ } ) )
981
998
} else if self . is_static_global ( ) {
982
999
// FOREIGN STATIC ITEM
983
1000
self . bump ( ) ; // `static`
@@ -1603,44 +1620,6 @@ impl ParamCfg {
1603
1620
1604
1621
/// Parsing of functions and methods.
1605
1622
impl < ' 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
-
1644
1623
/// Parse a function starting from the front matter (`const ...`) to the body `{ ... }` or `;`.
1645
1624
fn parse_fn (
1646
1625
& mut self ,
0 commit comments