Parse 'async unsafe fn' instead of 'unsafe async fn'.

This commit is contained in:
Mazdak Farrokhzad
2019-05-29 16:53:48 +02:00
parent 0bfbaa6e8d
commit 2ebfbb4fab
3 changed files with 36 additions and 39 deletions

View File

@@ -7205,20 +7205,16 @@ impl<'a> Parser<'a> {
return Ok(Some(item)); return Ok(Some(item));
} }
// `unsafe async fn` or `async fn` // Parse `async unsafe? fn`.
if ( if self.check_keyword(kw::Async) {
self.check_keyword(kw::Unsafe) && let async_span = self.span;
self.is_keyword_ahead(1, &[kw::Async]) if self.is_keyword_ahead(1, &[kw::Fn])
) || ( || self.is_keyword_ahead(2, &[kw::Fn])
self.check_keyword(kw::Async) &&
self.is_keyword_ahead(1, &[kw::Fn])
)
{ {
// ASYNC FUNCTION ITEM // ASYNC FUNCTION ITEM
let unsafety = self.parse_unsafety(); self.bump(); // `async`
self.expect_keyword(kw::Async)?; let unsafety = self.parse_unsafety(); // `unsafe`?
let async_span = self.prev_span; self.expect_keyword(kw::Fn)?; // `fn`
self.expect_keyword(kw::Fn)?;
let fn_span = self.prev_span; let fn_span = self.prev_span;
let (ident, item_, extra_attrs) = let (ident, item_, extra_attrs) =
self.parse_item_fn(unsafety, self.parse_item_fn(unsafety,
@@ -7244,6 +7240,7 @@ impl<'a> Parser<'a> {
} }
return Ok(Some(item)); return Ok(Some(item));
} }
}
if self.check_keyword(kw::Unsafe) && if self.check_keyword(kw::Unsafe) &&
self.is_keyword_ahead(1, &[kw::Trait, kw::Auto]) self.is_keyword_ahead(1, &[kw::Trait, kw::Auto])
{ {

View File

@@ -122,7 +122,7 @@ fn async_fn_with_internal_borrow(y: u8) -> impl Future<Output = u8> {
} }
} }
unsafe async fn unsafe_async_fn(x: u8) -> u8 { async unsafe fn unsafe_async_fn(x: u8) -> u8 {
wake_and_yield_once().await; wake_and_yield_once().await;
x x
} }

View File

@@ -122,7 +122,7 @@ fn async_fn_with_internal_borrow(y: u8) -> impl Future<Output = u8> {
} }
} }
unsafe async fn unsafe_async_fn(x: u8) -> u8 { async unsafe fn unsafe_async_fn(x: u8) -> u8 {
await!(wake_and_yield_once()); await!(wake_and_yield_once());
x x
} }