@@ -4611,7 +4611,7 @@ impl<'a> Parser<'a> {
4611
4611
}
4612
4612
4613
4613
/// 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 > ) > {
4615
4615
maybe_whole ! ( self , NtBlock , |x| ( Vec :: new( ) , x) ) ;
4616
4616
4617
4617
let lo = self . token . span ;
@@ -6698,15 +6698,20 @@ impl<'a> Parser<'a> {
6698
6698
}
6699
6699
6700
6700
/// 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 > {
6703
6708
self . expect_keyword ( kw:: Fn ) ?;
6704
6709
6705
6710
let ( ident, mut generics) = self . parse_fn_header ( ) ?;
6706
6711
let decl = self . parse_fn_decl ( true ) ?;
6707
6712
generics. where_clause = self . parse_where_clause ( ) ?;
6708
6713
let hi = self . token . span ;
6709
- self . expect ( & token :: Semi ) ?;
6714
+ self . parse_semi_or_incorrect_foreign_fn_body ( & ident , extern_sp ) ?;
6710
6715
Ok ( ast:: ForeignItem {
6711
6716
ident,
6712
6717
attrs,
@@ -6833,12 +6838,14 @@ impl<'a> Parser<'a> {
6833
6838
/// extern "C" {}
6834
6839
/// extern {}
6835
6840
/// ```
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 > > {
6842
6849
self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
6843
6850
6844
6851
let abi = opt_abi. unwrap_or ( Abi :: C ) ;
@@ -6847,7 +6854,7 @@ impl<'a> Parser<'a> {
6847
6854
6848
6855
let mut foreign_items = vec ! [ ] ;
6849
6856
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 ) ?) ;
6851
6858
}
6852
6859
6853
6860
let prev_span = self . prev_span ;
@@ -7094,6 +7101,7 @@ impl<'a> Parser<'a> {
7094
7101
}
7095
7102
7096
7103
if self . eat_keyword ( kw:: Extern ) {
7104
+ let extern_sp = self . prev_span ;
7097
7105
if self . eat_keyword ( kw:: Crate ) {
7098
7106
return Ok ( Some ( self . parse_item_extern_crate ( lo, visibility, attrs) ?) ) ;
7099
7107
}
@@ -7117,7 +7125,9 @@ impl<'a> Parser<'a> {
7117
7125
maybe_append ( attrs, extra_attrs) ) ;
7118
7126
return Ok ( Some ( item) ) ;
7119
7127
} 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
+ ) ) ;
7121
7131
}
7122
7132
7123
7133
self . unexpected ( ) ?;
@@ -7502,7 +7512,7 @@ impl<'a> Parser<'a> {
7502
7512
}
7503
7513
7504
7514
/// 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 > {
7506
7516
maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
7507
7517
7508
7518
let attrs = self . parse_outer_attributes ( ) ?;
@@ -7527,7 +7537,7 @@ impl<'a> Parser<'a> {
7527
7537
}
7528
7538
// FOREIGN FUNCTION ITEM
7529
7539
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 ) ?) ;
7531
7541
}
7532
7542
// FOREIGN TYPE ITEM
7533
7543
if self . check_keyword ( kw:: Type ) {
0 commit comments