Flesh out a few more tests

This commit is contained in:
Michael Goulet 2024-02-26 23:06:38 +00:00
parent 2252ff7302
commit c8e3f35eb6
4 changed files with 36 additions and 9 deletions

View File

@ -8,11 +8,15 @@
fn main() {
block_on::block_on(async {
let x = async || {};
async fn needs_async_fn_once(x: impl async FnOnce()) {
x().await;
}
needs_async_fn_once(x).await;
needs_async_fn_once(async || {}).await;
needs_async_fn_once(|| async {}).await;
async fn foo() {}
needs_async_fn_once(foo).await;
});
}

View File

@ -2,7 +2,7 @@
//@ edition:2021
//@ build-pass
#![feature(async_closure)]
#![feature(async_closure, async_fn_traits)]
extern crate block_on;
@ -15,7 +15,11 @@ fn main() {
c().await;
c().await;
fn is_static<T: 'static>(_: T) {}
is_static(c);
fn is_static<T: 'static>(_: &T) {}
is_static(&c);
// Check that `<{async fn} as AsyncFnOnce>::CallOnceFuture` owns its captures.
fn call_once<F: async FnOnce()>(f: F) -> F::CallOnceFuture { f() }
is_static(&call_once(c));
});
}

View File

@ -2,8 +2,6 @@
//@ edition:2021
//@ build-pass
// check that `&{async-closure}` implements `AsyncFn`.
#![feature(async_closure)]
extern crate block_on;
@ -13,6 +11,15 @@
fn main() {
block_on::block_on(async {
async fn call_once(x: impl async Fn()) { x().await }
call_once(&async || {}).await
// check that `&{async-closure}` implements `async Fn`.
call_once(&async || {}).await;
// check that `&{closure}` implements `async Fn`.
call_once(&|| async {}).await;
// check that `&fndef` implements `async Fn`.
async fn foo() {}
call_once(&foo).await;
});
}

View File

@ -0,0 +1,12 @@
//@ edition:2018
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@ check-pass
#![feature(async_closure, unboxed_closures, async_fn_traits)]
fn project<F: async Fn<()>>(_: F) -> Option<F::Output> { None }
fn main() {
let x: Option<i32> = project(|| async { 1i32 });
}