Skip to content

Commit

Permalink
test unsafe fn and async unsafe fn calls in unsafe { async || }
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Jul 12, 2019
1 parent d023e47 commit 5f8d0a1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/test/ui/async-await/async-await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// edition:2018
// aux-build:arc_wake.rs

#![feature(async_await, async_closure)]
#![feature(async_await)]

extern crate arc_wake;

Expand Down Expand Up @@ -70,7 +70,7 @@ fn async_nonmove_block(x: u8) -> impl Future<Output = u8> {
}
}

// see async-closure.rs for async_closure
// see async-closure.rs for async_closure + async_closure_in_unsafe_block

async fn async_fn(x: u8) -> u8 {
wake_and_yield_once().await;
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/async-await/async-closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ fn async_closure(x: u8) -> impl Future<Output = u8> {
})(x)
}

fn async_closure_in_unsafe_block(x: u8) -> impl Future<Output = u8> {
(unsafe {
async move |x: u8| unsafe_fn(unsafe_async_fn(x).await)
})(x)
}

async unsafe fn unsafe_async_fn(x: u8) -> u8 {
wake_and_yield_once().await;
x
}

unsafe fn unsafe_fn(x: u8) -> u8 {
x
}

fn test_future_yields_once_then_returns<F, Fut>(f: F)
where
F: FnOnce(u8) -> Fut,
Expand All @@ -77,5 +92,6 @@ fn main() {

test! {
async_closure,
async_closure_in_unsafe_block,
}
}
7 changes: 7 additions & 0 deletions src/test/ui/async-await/await-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ fn async_closure(x: u8) -> impl Future<Output = u8> {
})(x)
}

fn async_closure_in_unsafe_block(x: u8) -> impl Future<Output = u8> {
(unsafe {
async move |x: u8| unsafe_fn(await!(unsafe_async_fn(x)))
})(x)
}

async fn async_fn(x: u8) -> u8 {
await!(wake_and_yield_once());
x
Expand Down Expand Up @@ -193,6 +199,7 @@ fn main() {
async_block,
async_nonmove_block,
async_closure,
async_closure_in_unsafe_block,
async_fn,
generic_async_fn,
async_fn_with_internal_borrow,
Expand Down

0 comments on commit 5f8d0a1

Please sign in to comment.