@@ -114,7 +114,7 @@ impl<'a> Parser<'a> {
114114 unsafety : Unsafety :: Normal ,
115115 asyncness : respan ( fn_span, IsAsync :: NotAsync ) ,
116116 constness : respan ( fn_span, Constness :: NotConst ) ,
117- abi,
117+ ext : Extern :: from_abi ( abi) ,
118118 } ;
119119 return self . parse_item_fn ( lo, vis, attrs, header) ;
120120 } else if self . check ( & token:: OpenDelim ( token:: Brace ) ) {
@@ -143,14 +143,14 @@ impl<'a> Parser<'a> {
143143 if self . check_keyword ( kw:: Extern ) {
144144 self . sess . gated_spans . gate ( sym:: const_extern_fn, lo. to ( self . token . span ) ) ;
145145 }
146- let abi = self . parse_extern_abi ( ) ?;
146+ let ext = self . parse_extern ( ) ?;
147147 self . bump ( ) ; // `fn`
148148
149149 let header = FnHeader {
150150 unsafety,
151151 asyncness : respan ( const_span, IsAsync :: NotAsync ) ,
152152 constness : respan ( const_span, Constness :: Const ) ,
153- abi ,
153+ ext ,
154154 } ;
155155 return self . parse_item_fn ( lo, vis, attrs, header) ;
156156 }
@@ -193,7 +193,7 @@ impl<'a> Parser<'a> {
193193 unsafety,
194194 asyncness,
195195 constness : respan ( fn_span, Constness :: NotConst ) ,
196- abi : Abi :: new ( sym :: Rust , fn_span ) ,
196+ ext : Extern :: None ,
197197 } ;
198198 return self . parse_item_fn ( lo, vis, attrs, header) ;
199199 }
@@ -230,7 +230,7 @@ impl<'a> Parser<'a> {
230230 unsafety : Unsafety :: Normal ,
231231 asyncness : respan ( fn_span, IsAsync :: NotAsync ) ,
232232 constness : respan ( fn_span, Constness :: NotConst ) ,
233- abi : Abi :: new ( sym :: Rust , fn_span ) ,
233+ ext : Extern :: None ,
234234 } ;
235235 return self . parse_item_fn ( lo, vis, attrs, header) ;
236236 }
@@ -242,14 +242,14 @@ impl<'a> Parser<'a> {
242242 self . bump ( ) ; // `unsafe`
243243 // `{` is also expected after `unsafe`; in case of error, include it in the diagnostic.
244244 self . check ( & token:: OpenDelim ( token:: Brace ) ) ;
245- let abi = self . parse_extern_abi ( ) ?;
245+ let ext = self . parse_extern ( ) ?;
246246 self . expect_keyword ( kw:: Fn ) ?;
247247 let fn_span = self . prev_span ;
248248 let header = FnHeader {
249249 unsafety : Unsafety :: Unsafe ,
250250 asyncness : respan ( fn_span, IsAsync :: NotAsync ) ,
251251 constness : respan ( fn_span, Constness :: NotConst ) ,
252- abi ,
252+ ext ,
253253 } ;
254254 return self . parse_item_fn ( lo, vis, attrs, header) ;
255255 }
@@ -1100,7 +1100,7 @@ impl<'a> Parser<'a> {
11001100 fn parse_item_foreign_mod (
11011101 & mut self ,
11021102 lo : Span ,
1103- abi : Abi ,
1103+ abi : Option < Abi > ,
11041104 visibility : Visibility ,
11051105 mut attrs : Vec < Attribute > ,
11061106 extern_sp : Span ,
@@ -1775,9 +1775,16 @@ impl<'a> Parser<'a> {
17751775 attrs : Vec < Attribute > ,
17761776 header : FnHeader ,
17771777 ) -> 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 == sym:: C ,
1782+ } ;
17781783 let ( ident, decl, generics) = self . parse_fn_sig ( ParamCfg {
17791784 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 ,
17811788 is_name_required : |_| true ,
17821789 } ) ?;
17831790 let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
@@ -1905,19 +1912,19 @@ impl<'a> Parser<'a> {
19051912 }
19061913 let asyncness = respan ( self . prev_span , asyncness) ;
19071914 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 )
19101917 } 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 )
19131920 } ;
19141921 if !self . eat_keyword ( kw:: Fn ) {
19151922 // It is possible for `expect_one_of` to recover given the contents of
19161923 // `self.expected_tokens`, therefore, do not use `self.unexpected()` which doesn't
19171924 // account for this.
19181925 if !self . expect_one_of ( & [ ] , & [ ] ) ? { unreachable ! ( ) }
19191926 }
1920- Ok ( FnHeader { constness, unsafety, asyncness, abi } )
1927+ Ok ( FnHeader { constness, unsafety, asyncness, ext } )
19211928 }
19221929
19231930 /// Parse the "signature", including the identifier, parameters, and generics of a function.
0 commit comments