From caad6ee2404cbe49915052f342b6227437e4d2a9 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 19 Mar 2026 19:10:21 +0100 Subject: [PATCH] tests: Add regression test for async closures involving HRTBs I suspect the original code had several issues. The last one that made the code compile entered `nightly-2024-02-11`. The code fails to build with `nightly-2024-02-10`: $ rustc +nightly-2024-02-10 --edition 2018 tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs error[E0277]: expected a `FnOnce(&u8)` closure, found `{coroutine-closure@tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs:31:9: 31:30}` --> tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs:31:9 | 31 | foo(async move | f: &u8 | { *f }); | --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `FnOnce(&u8)` closure, found `{coroutine-closure@tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs:31:9: 31:30}` | | | required by a bound introduced by this call | (Note that you must add `#![feature(async_closure)]` to test with such old nightlies, since they are from before stabilization of async closures.) This was probably fixed by 3bb384aad6e7f6. --- .../unifying-function-types-involving-hrtb.rs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs diff --git a/tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs b/tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs new file mode 100644 index 0000000000000..05505206b7139 --- /dev/null +++ b/tests/ui/async-await/async-closures/unifying-function-types-involving-hrtb.rs @@ -0,0 +1,33 @@ +//! Regresssion test for . + +//@ edition:2018 +//@ check-pass + +use std::future::Future; + +trait Foo<'a> { + type Future: Future + 'a; + + fn start(self, f: &'a u8) -> Self::Future; +} + +impl<'a, Fn, Fut> Foo<'a> for Fn +where + Fn: FnOnce(&'a u8) -> Fut, + Fut: Future + 'a, +{ + type Future = Fut; + + fn start(self, f: &'a u8) -> Self::Future { (self)(f) } +} + +fn foo(f: F) where F: for<'a> Foo<'a> { + let bar = 5; + f.start(&bar); +} + +fn main() { + foo(async move | f: &u8 | { *f }); + + foo({ async fn baz(f: &u8) -> u8 { *f } baz }); +}