@@ -4615,7 +4615,7 @@ impl<'a> Parser<'a> {
46154615 }
46164616
46174617 /// Parses a block. Inner attributes are allowed.
4618- fn parse_inner_attrs_and_block ( & mut self ) -> PResult < ' a , ( Vec < Attribute > , P < Block > ) > {
4618+ crate fn parse_inner_attrs_and_block ( & mut self ) -> PResult < ' a , ( Vec < Attribute > , P < Block > ) > {
46194619 maybe_whole ! ( self , NtBlock , |x| ( Vec :: new( ) , x) ) ;
46204620
46214621 let lo = self . token . span ;
@@ -6700,15 +6700,20 @@ impl<'a> Parser<'a> {
67006700 }
67016701
67026702 /// Parses a function declaration from a foreign module.
6703- fn parse_item_foreign_fn ( & mut self , vis : ast:: Visibility , lo : Span , attrs : Vec < Attribute > )
6704- -> PResult < ' a , ForeignItem > {
6703+ fn parse_item_foreign_fn (
6704+ & mut self ,
6705+ vis : ast:: Visibility ,
6706+ lo : Span ,
6707+ attrs : Vec < Attribute > ,
6708+ extern_sp : Span ,
6709+ ) -> PResult < ' a , ForeignItem > {
67056710 self . expect_keyword ( kw:: Fn ) ?;
67066711
67076712 let ( ident, mut generics) = self . parse_fn_header ( ) ?;
67086713 let decl = self . parse_fn_decl ( true ) ?;
67096714 generics. where_clause = self . parse_where_clause ( ) ?;
67106715 let hi = self . token . span ;
6711- self . expect ( & token :: Semi ) ?;
6716+ self . parse_semi_or_incorrect_foreign_fn_body ( & ident , extern_sp ) ?;
67126717 Ok ( ast:: ForeignItem {
67136718 ident,
67146719 attrs,
@@ -6835,12 +6840,14 @@ impl<'a> Parser<'a> {
68356840 /// extern "C" {}
68366841 /// extern {}
68376842 /// ```
6838- fn parse_item_foreign_mod ( & mut self ,
6839- lo : Span ,
6840- opt_abi : Option < Abi > ,
6841- visibility : Visibility ,
6842- mut attrs : Vec < Attribute > )
6843- -> PResult < ' a , P < Item > > {
6843+ fn parse_item_foreign_mod (
6844+ & mut self ,
6845+ lo : Span ,
6846+ opt_abi : Option < Abi > ,
6847+ visibility : Visibility ,
6848+ mut attrs : Vec < Attribute > ,
6849+ extern_sp : Span ,
6850+ ) -> PResult < ' a , P < Item > > {
68446851 self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
68456852
68466853 let abi = opt_abi. unwrap_or ( Abi :: C ) ;
@@ -6849,7 +6856,7 @@ impl<'a> Parser<'a> {
68496856
68506857 let mut foreign_items = vec ! [ ] ;
68516858 while !self . eat ( & token:: CloseDelim ( token:: Brace ) ) {
6852- foreign_items. push ( self . parse_foreign_item ( ) ?) ;
6859+ foreign_items. push ( self . parse_foreign_item ( extern_sp ) ?) ;
68536860 }
68546861
68556862 let prev_span = self . prev_span ;
@@ -7096,6 +7103,7 @@ impl<'a> Parser<'a> {
70967103 }
70977104
70987105 if self . eat_keyword ( kw:: Extern ) {
7106+ let extern_sp = self . prev_span ;
70997107 if self . eat_keyword ( kw:: Crate ) {
71007108 return Ok ( Some ( self . parse_item_extern_crate ( lo, visibility, attrs) ?) ) ;
71017109 }
@@ -7119,7 +7127,9 @@ impl<'a> Parser<'a> {
71197127 maybe_append ( attrs, extra_attrs) ) ;
71207128 return Ok ( Some ( item) ) ;
71217129 } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
7122- return Ok ( Some ( self . parse_item_foreign_mod ( lo, opt_abi, visibility, attrs) ?) ) ;
7130+ return Ok ( Some (
7131+ self . parse_item_foreign_mod ( lo, opt_abi, visibility, attrs, extern_sp) ?,
7132+ ) ) ;
71237133 }
71247134
71257135 self . unexpected ( ) ?;
@@ -7504,7 +7514,7 @@ impl<'a> Parser<'a> {
75047514 }
75057515
75067516 /// Parses a foreign item.
7507- crate fn parse_foreign_item ( & mut self ) -> PResult < ' a , ForeignItem > {
7517+ crate fn parse_foreign_item ( & mut self , extern_sp : Span ) -> PResult < ' a , ForeignItem > {
75087518 maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
75097519
75107520 let attrs = self . parse_outer_attributes ( ) ?;
@@ -7529,7 +7539,7 @@ impl<'a> Parser<'a> {
75297539 }
75307540 // FOREIGN FUNCTION ITEM
75317541 if self . check_keyword ( kw:: Fn ) {
7532- return Ok ( self . parse_item_foreign_fn ( visibility, lo, attrs) ?) ;
7542+ return Ok ( self . parse_item_foreign_fn ( visibility, lo, attrs, extern_sp ) ?) ;
75337543 }
75347544 // FOREIGN TYPE ITEM
75357545 if self . check_keyword ( kw:: Type ) {
0 commit comments