Skip to content

Commit caad6ee

Browse files
committed
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 3bb384a.
1 parent 1e21831 commit caad6ee

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//! Regresssion test for <https://github.com/rust-lang/rust/issues/59337>.
2+
3+
//@ edition:2018
4+
//@ check-pass
5+
6+
use std::future::Future;
7+
8+
trait Foo<'a> {
9+
type Future: Future<Output = u8> + 'a;
10+
11+
fn start(self, f: &'a u8) -> Self::Future;
12+
}
13+
14+
impl<'a, Fn, Fut> Foo<'a> for Fn
15+
where
16+
Fn: FnOnce(&'a u8) -> Fut,
17+
Fut: Future<Output = u8> + 'a,
18+
{
19+
type Future = Fut;
20+
21+
fn start(self, f: &'a u8) -> Self::Future { (self)(f) }
22+
}
23+
24+
fn foo<F>(f: F) where F: for<'a> Foo<'a> {
25+
let bar = 5;
26+
f.start(&bar);
27+
}
28+
29+
fn main() {
30+
foo(async move | f: &u8 | { *f });
31+
32+
foo({ async fn baz(f: &u8) -> u8 { *f } baz });
33+
}

0 commit comments

Comments
 (0)