align async-await.rs and await-macro.rs with one another

This commit is contained in:
Delan Azabani 2019-07-12 13:04:41 +10:00
parent e31911ef8f
commit 1574c2dee2
2 changed files with 20 additions and 3 deletions

View File

@ -3,7 +3,7 @@
// edition:2018
// aux-build:arc_wake.rs
#![feature(async_await)]
#![feature(async_await, async_closure)]
extern crate arc_wake;
@ -70,6 +70,13 @@ fn async_nonmove_block(x: u8) -> impl Future<Output = u8> {
}
}
fn async_closure(x: u8) -> impl Future<Output = u8> {
(async move |x: u8| -> u8 {
wake_and_yield_once().await;
x
})(x)
}
async fn async_fn(x: u8) -> u8 {
wake_and_yield_once().await;
x
@ -173,6 +180,7 @@ macro_rules! test_with_borrow {
test! {
async_block,
async_nonmove_block,
async_closure,
async_fn,
generic_async_fn,
async_fn_with_internal_borrow,

View File

@ -134,11 +134,15 @@ fn foo() {}
}
impl Foo {
async fn async_method(x: u8) -> u8 {
async fn async_assoc_item(x: u8) -> u8 {
unsafe {
await!(unsafe_async_fn(x))
}
}
async unsafe fn async_unsafe_assoc_item(x: u8) -> u8 {
await!(unsafe_async_fn(x))
}
}
fn test_future_yields_once_then_returns<F, Fut>(f: F)
@ -180,12 +184,17 @@ macro_rules! test_with_borrow {
async_fn,
generic_async_fn,
async_fn_with_internal_borrow,
Foo::async_method,
Foo::async_assoc_item,
|x| {
async move {
unsafe { await!(unsafe_async_fn(x)) }
}
},
|x| {
async move {
unsafe { await!(Foo::async_unsafe_assoc_item(x)) }
}
},
}
test_with_borrow! {
async_block_with_borrow_named_lifetime,