mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
test unsafe fn
and async unsafe fn
calls in unsafe { async || }
This commit is contained in:
parent
d023e47877
commit
5f8d0a1920
@ -3,7 +3,7 @@
|
||||
// edition:2018
|
||||
// aux-build:arc_wake.rs
|
||||
|
||||
#![feature(async_await, async_closure)]
|
||||
#![feature(async_await)]
|
||||
|
||||
extern crate arc_wake;
|
||||
|
||||
@ -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;
|
||||
|
@ -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,
|
||||
@ -77,5 +92,6 @@ fn main() {
|
||||
|
||||
test! {
|
||||
async_closure,
|
||||
async_closure_in_unsafe_block,
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user