Parse unsafe async fn instead of async unsafe fn

This commit is contained in:
Taylor Cramer 2018-06-18 16:49:34 -07:00
parent cf844b547d
commit 09f6caabe5
2 changed files with 23 additions and 4 deletions

View File

@ -6744,13 +6744,19 @@ impl<'a> Parser<'a> {
maybe_append(attrs, extra_attrs));
return Ok(Some(item));
}
if self.check_keyword(keywords::Async) &&
(self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) ||
self.look_ahead(1, |t| t.is_keyword(keywords::Unsafe)))
// `unsafe async fn` or `async fn`
if (
self.check_keyword(keywords::Unsafe) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Async))
) || (
self.check_keyword(keywords::Async) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Fn))
)
{
// ASYNC FUNCTION ITEM
self.expect_keyword(keywords::Async)?;
let unsafety = self.parse_unsafety();
self.expect_keyword(keywords::Async)?;
self.expect_keyword(keywords::Fn)?;
let fn_span = self.prev_span;
let (ident, item_, extra_attrs) =

View File

@ -99,6 +99,19 @@ fn async_fn_with_internal_borrow(y: u8) -> impl Future<Output = u8> {
}
}
unsafe async fn unsafe_async_fn(x: u8) -> u8 {
await!(wake_and_yield_once());
x
}
struct Foo {
async fn async_method(x: u8) -> u8 {
unsafe {
await!(unsafe_async_fn())
}
}
}
fn test_future_yields_once_then_returns<F, Fut>(f: F)
where
F: FnOnce(u8) -> Fut,