@@ -4615,7 +4615,7 @@ impl<'a> Parser<'a> {
4615
4615
}
4616
4616
4617
4617
/// 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 > ) > {
4619
4619
maybe_whole ! ( self , NtBlock , |x| ( Vec :: new( ) , x) ) ;
4620
4620
4621
4621
let lo = self . token . span ;
@@ -6700,15 +6700,20 @@ impl<'a> Parser<'a> {
6700
6700
}
6701
6701
6702
6702
/// 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 > {
6705
6710
self . expect_keyword ( kw:: Fn ) ?;
6706
6711
6707
6712
let ( ident, mut generics) = self . parse_fn_header ( ) ?;
6708
6713
let decl = self . parse_fn_decl ( true ) ?;
6709
6714
generics. where_clause = self . parse_where_clause ( ) ?;
6710
6715
let hi = self . token . span ;
6711
- self . expect ( & token :: Semi ) ?;
6716
+ self . parse_semi_or_incorrect_foreign_fn_body ( & ident , extern_sp ) ?;
6712
6717
Ok ( ast:: ForeignItem {
6713
6718
ident,
6714
6719
attrs,
@@ -6835,12 +6840,14 @@ impl<'a> Parser<'a> {
6835
6840
/// extern "C" {}
6836
6841
/// extern {}
6837
6842
/// ```
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 > > {
6844
6851
self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
6845
6852
6846
6853
let abi = opt_abi. unwrap_or ( Abi :: C ) ;
@@ -6849,7 +6856,7 @@ impl<'a> Parser<'a> {
6849
6856
6850
6857
let mut foreign_items = vec ! [ ] ;
6851
6858
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 ) ?) ;
6853
6860
}
6854
6861
6855
6862
let prev_span = self . prev_span ;
@@ -7096,6 +7103,7 @@ impl<'a> Parser<'a> {
7096
7103
}
7097
7104
7098
7105
if self . eat_keyword ( kw:: Extern ) {
7106
+ let extern_sp = self . prev_span ;
7099
7107
if self . eat_keyword ( kw:: Crate ) {
7100
7108
return Ok ( Some ( self . parse_item_extern_crate ( lo, visibility, attrs) ?) ) ;
7101
7109
}
@@ -7119,7 +7127,9 @@ impl<'a> Parser<'a> {
7119
7127
maybe_append ( attrs, extra_attrs) ) ;
7120
7128
return Ok ( Some ( item) ) ;
7121
7129
} 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
+ ) ) ;
7123
7133
}
7124
7134
7125
7135
self . unexpected ( ) ?;
@@ -7504,7 +7514,7 @@ impl<'a> Parser<'a> {
7504
7514
}
7505
7515
7506
7516
/// 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 > {
7508
7518
maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
7509
7519
7510
7520
let attrs = self . parse_outer_attributes ( ) ?;
@@ -7529,7 +7539,7 @@ impl<'a> Parser<'a> {
7529
7539
}
7530
7540
// FOREIGN FUNCTION ITEM
7531
7541
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 ) ?) ;
7533
7543
}
7534
7544
// FOREIGN TYPE ITEM
7535
7545
if self . check_keyword ( kw:: Type ) {
0 commit comments