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