@@ -1205,27 +1205,41 @@ impl<'a> Parser<'a> {
1205
1205
Ok ( ( ) )
1206
1206
}
1207
1207
1208
- /// Parses `extern` followed by an optional ABI string, or nothing.
1208
+ /// Parses `extern string_literal?`.
1209
+ /// If `extern` is not found, the Rust ABI is used.
1210
+ /// If `extern` is found and a `string_literal` does not follow, the C ABI is used.
1209
1211
fn parse_extern_abi ( & mut self ) -> PResult < ' a , Abi > {
1210
1212
Ok ( if self . eat_keyword ( kw:: Extern ) {
1211
- let ext_sp = self . prev_span ;
1212
- self . parse_opt_abi ( ) ?. unwrap_or_else ( || Abi :: new ( sym:: C , ext_sp) )
1213
+ self . parse_opt_abi ( ) ?
1213
1214
} else {
1214
1215
Abi :: default ( )
1215
1216
} )
1216
1217
}
1217
1218
1218
- /// Parses a string as an ABI spec on an extern type or module.
1219
- fn parse_opt_abi ( & mut self ) -> PResult < ' a , Option < Abi > > {
1220
- match self . token . kind {
1221
- token:: Literal ( token:: Lit { kind : token:: Str , symbol, suffix } ) |
1222
- token:: Literal ( token:: Lit { kind : token:: StrRaw ( ..) , symbol, suffix } ) => {
1223
- self . expect_no_suffix ( self . token . span , "an ABI spec" , suffix) ;
1224
- self . bump ( ) ;
1225
- Ok ( Some ( Abi :: new ( symbol, self . prev_span ) ) )
1219
+ /// Parses a string literal as an ABI spec.
1220
+ /// If one is not found, the "C" ABI is used.
1221
+ fn parse_opt_abi ( & mut self ) -> PResult < ' a , Abi > {
1222
+ let span = if self . token . can_begin_literal_or_bool ( ) {
1223
+ let ast:: Lit { span, kind, .. } = self . parse_lit ( ) ?;
1224
+ match kind {
1225
+ ast:: LitKind :: Str ( symbol, _) => return Ok ( Abi :: new ( symbol, span) ) ,
1226
+ ast:: LitKind :: Err ( _) => { }
1227
+ _ => {
1228
+ self . struct_span_err ( span, "non-string ABI literal" )
1229
+ . span_suggestion (
1230
+ span,
1231
+ "specify the ABI with a string literal" ,
1232
+ "\" C\" " . to_string ( ) ,
1233
+ Applicability :: MaybeIncorrect ,
1234
+ )
1235
+ . emit ( ) ;
1236
+ }
1226
1237
}
1227
- _ => Ok ( None ) ,
1228
- }
1238
+ span
1239
+ } else {
1240
+ self . prev_span
1241
+ } ;
1242
+ Ok ( Abi :: new ( sym:: C , span) )
1229
1243
}
1230
1244
1231
1245
/// We are parsing `async fn`. If we are on Rust 2015, emit an error.
0 commit comments