@@ -4611,7 +4611,7 @@ impl<'a> Parser<'a> {
46114611 }
46124612
46134613 /// Parses a block. Inner attributes are allowed.
4614- fn parse_inner_attrs_and_block ( & mut self ) -> PResult < ' a , ( Vec < Attribute > , P < Block > ) > {
4614+ crate fn parse_inner_attrs_and_block ( & mut self ) -> PResult < ' a , ( Vec < Attribute > , P < Block > ) > {
46154615 maybe_whole ! ( self , NtBlock , |x| ( Vec :: new( ) , x) ) ;
46164616
46174617 let lo = self . token . span ;
@@ -6698,15 +6698,20 @@ impl<'a> Parser<'a> {
66986698 }
66996699
67006700 /// Parses a function declaration from a foreign module.
6701- fn parse_item_foreign_fn ( & mut self , vis : ast:: Visibility , lo : Span , attrs : Vec < Attribute > )
6702- -> PResult < ' a , ForeignItem > {
6701+ fn parse_item_foreign_fn (
6702+ & mut self ,
6703+ vis : ast:: Visibility ,
6704+ lo : Span ,
6705+ attrs : Vec < Attribute > ,
6706+ extern_sp : Span ,
6707+ ) -> PResult < ' a , ForeignItem > {
67036708 self . expect_keyword ( kw:: Fn ) ?;
67046709
67056710 let ( ident, mut generics) = self . parse_fn_header ( ) ?;
67066711 let decl = self . parse_fn_decl ( true ) ?;
67076712 generics. where_clause = self . parse_where_clause ( ) ?;
67086713 let hi = self . token . span ;
6709- self . expect ( & token :: Semi ) ?;
6714+ self . parse_semi_or_incorrect_foreign_fn_body ( & ident , extern_sp ) ?;
67106715 Ok ( ast:: ForeignItem {
67116716 ident,
67126717 attrs,
@@ -6833,12 +6838,14 @@ impl<'a> Parser<'a> {
68336838 /// extern "C" {}
68346839 /// extern {}
68356840 /// ```
6836- fn parse_item_foreign_mod ( & mut self ,
6837- lo : Span ,
6838- opt_abi : Option < Abi > ,
6839- visibility : Visibility ,
6840- mut attrs : Vec < Attribute > )
6841- -> PResult < ' a , P < Item > > {
6841+ fn parse_item_foreign_mod (
6842+ & mut self ,
6843+ lo : Span ,
6844+ opt_abi : Option < Abi > ,
6845+ visibility : Visibility ,
6846+ mut attrs : Vec < Attribute > ,
6847+ extern_sp : Span ,
6848+ ) -> PResult < ' a , P < Item > > {
68426849 self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
68436850
68446851 let abi = opt_abi. unwrap_or ( Abi :: C ) ;
@@ -6847,7 +6854,7 @@ impl<'a> Parser<'a> {
68476854
68486855 let mut foreign_items = vec ! [ ] ;
68496856 while !self . eat ( & token:: CloseDelim ( token:: Brace ) ) {
6850- foreign_items. push ( self . parse_foreign_item ( ) ?) ;
6857+ foreign_items. push ( self . parse_foreign_item ( extern_sp ) ?) ;
68516858 }
68526859
68536860 let prev_span = self . prev_span ;
@@ -7094,6 +7101,7 @@ impl<'a> Parser<'a> {
70947101 }
70957102
70967103 if self . eat_keyword ( kw:: Extern ) {
7104+ let extern_sp = self . prev_span ;
70977105 if self . eat_keyword ( kw:: Crate ) {
70987106 return Ok ( Some ( self . parse_item_extern_crate ( lo, visibility, attrs) ?) ) ;
70997107 }
@@ -7117,7 +7125,9 @@ impl<'a> Parser<'a> {
71177125 maybe_append ( attrs, extra_attrs) ) ;
71187126 return Ok ( Some ( item) ) ;
71197127 } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
7120- return Ok ( Some ( self . parse_item_foreign_mod ( lo, opt_abi, visibility, attrs) ?) ) ;
7128+ return Ok ( Some (
7129+ self . parse_item_foreign_mod ( lo, opt_abi, visibility, attrs, extern_sp) ?,
7130+ ) ) ;
71217131 }
71227132
71237133 self . unexpected ( ) ?;
@@ -7502,7 +7512,7 @@ impl<'a> Parser<'a> {
75027512 }
75037513
75047514 /// Parses a foreign item.
7505- crate fn parse_foreign_item ( & mut self ) -> PResult < ' a , ForeignItem > {
7515+ crate fn parse_foreign_item ( & mut self , extern_sp : Span ) -> PResult < ' a , ForeignItem > {
75067516 maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
75077517
75087518 let attrs = self . parse_outer_attributes ( ) ?;
@@ -7527,7 +7537,7 @@ impl<'a> Parser<'a> {
75277537 }
75287538 // FOREIGN FUNCTION ITEM
75297539 if self . check_keyword ( kw:: Fn ) {
7530- return Ok ( self . parse_item_foreign_fn ( visibility, lo, attrs) ?) ;
7540+ return Ok ( self . parse_item_foreign_fn ( visibility, lo, attrs, extern_sp ) ?) ;
75317541 }
75327542 // FOREIGN TYPE ITEM
75337543 if self . check_keyword ( kw:: Type ) {
0 commit comments