@@ -5734,9 +5734,12 @@ impl<'a> Parser<'a> {
5734
5734
{
5735
5735
let is_const_fn = self . eat_keyword ( kw:: Const ) ;
5736
5736
let const_span = self . prev_span ;
5737
- let unsafety = self . parse_unsafety ( ) ;
5738
5737
let asyncness = self . parse_asyncness ( ) ;
5738
+ if let IsAsync :: Async { .. } = asyncness {
5739
+ self . ban_async_in_2015 ( self . prev_span ) ;
5740
+ }
5739
5741
let asyncness = respan ( self . prev_span , asyncness) ;
5742
+ let unsafety = self . parse_unsafety ( ) ;
5740
5743
let ( constness, unsafety, abi) = if is_const_fn {
5741
5744
( respan ( const_span, Constness :: Const ) , unsafety, Abi :: Rust )
5742
5745
} else {
@@ -7254,13 +7257,7 @@ impl<'a> Parser<'a> {
7254
7257
item_,
7255
7258
visibility,
7256
7259
maybe_append ( attrs, extra_attrs) ) ;
7257
- if self . token . span . rust_2015 ( ) {
7258
- self . diagnostic ( ) . struct_span_err_with_code (
7259
- async_span,
7260
- "`async fn` is not permitted in the 2015 edition" ,
7261
- DiagnosticId :: Error ( "E0670" . into ( ) )
7262
- ) . emit ( ) ;
7263
- }
7260
+ self . ban_async_in_2015 ( async_span) ;
7264
7261
return Ok ( Some ( item) ) ;
7265
7262
}
7266
7263
}
@@ -7534,6 +7531,19 @@ impl<'a> Parser<'a> {
7534
7531
self . parse_macro_use_or_failure ( attrs, macros_allowed, attributes_allowed, lo, visibility)
7535
7532
}
7536
7533
7534
+ /// We are parsing `async fn`. If we are on Rust 2015, emit an error.
7535
+ fn ban_async_in_2015 ( & self , async_span : Span ) {
7536
+ if async_span. rust_2015 ( ) {
7537
+ self . diagnostic ( )
7538
+ . struct_span_err_with_code (
7539
+ async_span,
7540
+ "`async fn` is not permitted in the 2015 edition" ,
7541
+ DiagnosticId :: Error ( "E0670" . into ( ) )
7542
+ )
7543
+ . emit ( ) ;
7544
+ }
7545
+ }
7546
+
7537
7547
/// Parses a foreign item.
7538
7548
crate fn parse_foreign_item ( & mut self ) -> PResult < ' a , ForeignItem > {
7539
7549
maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
0 commit comments