From c8e3f35eb631c35bc7aabf358b7ca5c2a7fbfd1e Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 26 Feb 2024 23:06:38 +0000 Subject: [PATCH] Flesh out a few more tests --- .../async-closures/async-fn-once-for-async-fn.rs | 10 +++++++--- .../async-await/async-closures/move-is-async-fn.rs | 10 +++++++--- tests/ui/async-await/async-closures/refd.rs | 13 ++++++++++--- tests/ui/async-await/async-fn/project.rs | 12 ++++++++++++ 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 tests/ui/async-await/async-fn/project.rs diff --git a/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs b/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs index 9c3b458cd3a..be436465315 100644 --- a/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs +++ b/tests/ui/async-await/async-closures/async-fn-once-for-async-fn.rs @@ -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; }); } diff --git a/tests/ui/async-await/async-closures/move-is-async-fn.rs b/tests/ui/async-await/async-closures/move-is-async-fn.rs index 0ccd137266d..79e2298f609 100644 --- a/tests/ui/async-await/async-closures/move-is-async-fn.rs +++ b/tests/ui/async-await/async-closures/move-is-async-fn.rs @@ -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) {} - is_static(c); + fn is_static(_: &T) {} + is_static(&c); + + // Check that `<{async fn} as AsyncFnOnce>::CallOnceFuture` owns its captures. + fn call_once(f: F) -> F::CallOnceFuture { f() } + is_static(&call_once(c)); }); } diff --git a/tests/ui/async-await/async-closures/refd.rs b/tests/ui/async-await/async-closures/refd.rs index 1d9bc1a601b..0b8d3d7aff5 100644 --- a/tests/ui/async-await/async-closures/refd.rs +++ b/tests/ui/async-await/async-closures/refd.rs @@ -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; }); } diff --git a/tests/ui/async-await/async-fn/project.rs b/tests/ui/async-await/async-fn/project.rs new file mode 100644 index 00000000000..302564bb951 --- /dev/null +++ b/tests/ui/async-await/async-fn/project.rs @@ -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) -> Option { None } + +fn main() { + let x: Option = project(|| async { 1i32 }); +}