@@ -5734,9 +5734,12 @@ impl<'a> Parser<'a> {
57345734 {
57355735 let is_const_fn = self . eat_keyword ( kw:: Const ) ;
57365736 let const_span = self . prev_span ;
5737- let unsafety = self . parse_unsafety ( ) ;
57385737 let asyncness = self . parse_asyncness ( ) ;
5738+ if let IsAsync :: Async { .. } = asyncness {
5739+ self . ban_async_in_2015 ( self . prev_span ) ;
5740+ }
57395741 let asyncness = respan ( self . prev_span , asyncness) ;
5742+ let unsafety = self . parse_unsafety ( ) ;
57405743 let ( constness, unsafety, abi) = if is_const_fn {
57415744 ( respan ( const_span, Constness :: Const ) , unsafety, Abi :: Rust )
57425745 } else {
@@ -7254,13 +7257,7 @@ impl<'a> Parser<'a> {
72547257 item_,
72557258 visibility,
72567259 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) ;
72647261 return Ok ( Some ( item) ) ;
72657262 }
72667263 }
@@ -7534,6 +7531,19 @@ impl<'a> Parser<'a> {
75347531 self . parse_macro_use_or_failure ( attrs, macros_allowed, attributes_allowed, lo, visibility)
75357532 }
75367533
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+
75377547 /// Parses a foreign item.
75387548 crate fn parse_foreign_item ( & mut self ) -> PResult < ' a , ForeignItem > {
75397549 maybe_whole ! ( self , NtForeignItem , |ni| ni) ;
0 commit comments