@@ -3,9 +3,9 @@ use super::diagnostics::{Error, dummy_arg, ConsumeClosingDelim};
3
3
4
4
use crate :: maybe_whole;
5
5
6
- use syntax:: ast:: { self , Abi , DUMMY_NODE_ID , Ident , Attribute , AttrKind , AttrStyle , AnonConst , Item } ;
6
+ use syntax:: ast:: { self , DUMMY_NODE_ID , Ident , Attribute , AttrKind , AttrStyle , AnonConst , Item } ;
7
7
use syntax:: ast:: { ItemKind , ImplItem , ImplItemKind , TraitItem , TraitItemKind , UseTree , UseTreeKind } ;
8
- use syntax:: ast:: { PathSegment , IsAuto , Constness , IsAsync , Unsafety , Defaultness } ;
8
+ use syntax:: ast:: { PathSegment , IsAuto , Constness , IsAsync , Unsafety , Defaultness , Extern , StrLit } ;
9
9
use syntax:: ast:: { Visibility , VisibilityKind , Mutability , FnHeader , ForeignItem , ForeignItemKind } ;
10
10
use syntax:: ast:: { Ty , TyKind , Generics , TraitRef , EnumDef , VariantData , StructField } ;
11
11
use syntax:: ast:: { Mac , MacDelimiter , Block , BindingMode , FnDecl , FnSig , SelfKind , Param } ;
@@ -105,7 +105,7 @@ impl<'a> Parser<'a> {
105
105
return Ok ( Some ( self . parse_item_extern_crate ( lo, vis, attrs) ?) ) ;
106
106
}
107
107
108
- let abi = self . parse_opt_abi ( ) ? ;
108
+ let abi = self . parse_abi ( ) ;
109
109
110
110
if self . eat_keyword ( kw:: Fn ) {
111
111
// EXTERN FUNCTION ITEM
@@ -114,7 +114,7 @@ impl<'a> Parser<'a> {
114
114
unsafety : Unsafety :: Normal ,
115
115
asyncness : respan ( fn_span, IsAsync :: NotAsync ) ,
116
116
constness : respan ( fn_span, Constness :: NotConst ) ,
117
- abi,
117
+ ext : Extern :: from_abi ( abi) ,
118
118
} ;
119
119
return self . parse_item_fn ( lo, vis, attrs, header) ;
120
120
} else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
@@ -143,14 +143,14 @@ impl<'a> Parser<'a> {
143
143
if self . check_keyword ( kw:: Extern ) {
144
144
self . sess . gated_spans . gate ( sym:: const_extern_fn, lo. to ( self . token . span ) ) ;
145
145
}
146
- let abi = self . parse_extern_abi ( ) ?;
146
+ let ext = self . parse_extern ( ) ?;
147
147
self . bump ( ) ; // `fn`
148
148
149
149
let header = FnHeader {
150
150
unsafety,
151
151
asyncness : respan ( const_span, IsAsync :: NotAsync ) ,
152
152
constness : respan ( const_span, Constness :: Const ) ,
153
- abi ,
153
+ ext ,
154
154
} ;
155
155
return self . parse_item_fn ( lo, vis, attrs, header) ;
156
156
}
@@ -193,7 +193,7 @@ impl<'a> Parser<'a> {
193
193
unsafety,
194
194
asyncness,
195
195
constness : respan ( fn_span, Constness :: NotConst ) ,
196
- abi : Abi :: new ( sym :: Rust , fn_span ) ,
196
+ ext : Extern :: None ,
197
197
} ;
198
198
return self . parse_item_fn ( lo, vis, attrs, header) ;
199
199
}
@@ -230,7 +230,7 @@ impl<'a> Parser<'a> {
230
230
unsafety : Unsafety :: Normal ,
231
231
asyncness : respan ( fn_span, IsAsync :: NotAsync ) ,
232
232
constness : respan ( fn_span, Constness :: NotConst ) ,
233
- abi : Abi :: new ( sym :: Rust , fn_span ) ,
233
+ ext : Extern :: None ,
234
234
} ;
235
235
return self . parse_item_fn ( lo, vis, attrs, header) ;
236
236
}
@@ -242,14 +242,14 @@ impl<'a> Parser<'a> {
242
242
self . bump ( ) ; // `unsafe`
243
243
// `{` is also expected after `unsafe`; in case of error, include it in the diagnostic.
244
244
self . check ( & token:: OpenDelim ( token:: Brace ) ) ;
245
- let abi = self . parse_extern_abi ( ) ?;
245
+ let ext = self . parse_extern ( ) ?;
246
246
self . expect_keyword ( kw:: Fn ) ?;
247
247
let fn_span = self . prev_span ;
248
248
let header = FnHeader {
249
249
unsafety : Unsafety :: Unsafe ,
250
250
asyncness : respan ( fn_span, IsAsync :: NotAsync ) ,
251
251
constness : respan ( fn_span, Constness :: NotConst ) ,
252
- abi ,
252
+ ext ,
253
253
} ;
254
254
return self . parse_item_fn ( lo, vis, attrs, header) ;
255
255
}
@@ -1100,7 +1100,7 @@ impl<'a> Parser<'a> {
1100
1100
fn parse_item_foreign_mod (
1101
1101
& mut self ,
1102
1102
lo : Span ,
1103
- abi : Abi ,
1103
+ abi : Option < StrLit > ,
1104
1104
visibility : Visibility ,
1105
1105
mut attrs : Vec < Attribute > ,
1106
1106
extern_sp : Span ,
@@ -1775,9 +1775,16 @@ impl<'a> Parser<'a> {
1775
1775
attrs : Vec < Attribute > ,
1776
1776
header : FnHeader ,
1777
1777
) -> PResult < ' a , Option < P < Item > > > {
1778
+ let is_c_abi = match header. ext {
1779
+ ast:: Extern :: None => false ,
1780
+ ast:: Extern :: Implicit => true ,
1781
+ ast:: Extern :: Explicit ( abi) => abi. symbol_unescaped == sym:: C ,
1782
+ } ;
1778
1783
let ( ident, decl, generics) = self . parse_fn_sig ( ParamCfg {
1779
1784
is_self_allowed : false ,
1780
- allow_c_variadic : header. abi . symbol == sym:: C && header. unsafety == Unsafety :: Unsafe ,
1785
+ // FIXME: Parsing should not depend on ABI or unsafety and
1786
+ // the variadic parameter should always be parsed.
1787
+ allow_c_variadic : is_c_abi && header. unsafety == Unsafety :: Unsafe ,
1781
1788
is_name_required : |_| true ,
1782
1789
} ) ?;
1783
1790
let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
@@ -1905,19 +1912,19 @@ impl<'a> Parser<'a> {
1905
1912
}
1906
1913
let asyncness = respan ( self . prev_span , asyncness) ;
1907
1914
let unsafety = self . parse_unsafety ( ) ;
1908
- let ( constness, unsafety, abi ) = if is_const_fn {
1909
- ( respan ( const_span, Constness :: Const ) , unsafety, Abi :: default ( ) )
1915
+ let ( constness, unsafety, ext ) = if is_const_fn {
1916
+ ( respan ( const_span, Constness :: Const ) , unsafety, Extern :: None )
1910
1917
} else {
1911
- let abi = self . parse_extern_abi ( ) ?;
1912
- ( respan ( self . prev_span , Constness :: NotConst ) , unsafety, abi )
1918
+ let ext = self . parse_extern ( ) ?;
1919
+ ( respan ( self . prev_span , Constness :: NotConst ) , unsafety, ext )
1913
1920
} ;
1914
1921
if !self . eat_keyword ( kw:: Fn ) {
1915
1922
// It is possible for `expect_one_of` to recover given the contents of
1916
1923
// `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
1917
1924
// account for this.
1918
1925
if !self . expect_one_of ( & [ ] , & [ ] ) ? { unreachable ! ( ) }
1919
1926
}
1920
- Ok ( FnHeader { constness, unsafety, asyncness, abi } )
1927
+ Ok ( FnHeader { constness, unsafety, asyncness, ext } )
1921
1928
}
1922
1929
1923
1930
/// Parse the "signature", including the identifier, parameters, and generics of a function.
0 commit comments