Async closure was just stabilized in 1.85, so I wanted to give it a try:
fn foo<F>(_: F)
where
F: AsyncFn(&()) -> &(),
{
}
fn main() {
// ok
foo(async |u: &()| { u });
// error: lifetime may not live long enough
let c = async |u: &()| { u };
foo(c);
}
error: lifetime may not live long enough
--> src/main.rs:12:28
|
12 | let c = async |u: &()| { u };
| - - ^^^^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of async closure `{async closure body@src/main.rs:12:28: 12:33}` contains a lifetime `'2`
| let's call the lifetime of this reference `'1`
error[E0308]: mismatched types
--> src/main.rs:13:5
|
13 | foo(c);
| ^^^^^^ one type is more general than the other
|
= note: expected reference `&()`
found reference `&()`
note: the lifetime requirement is introduced here
--> src/main.rs:3:24
|
3 | F: AsyncFn(&()) -> &(),
| ^^^
It seems to me that the type inference fails when lifting the async closure into a variable. Is it related to this issue? Thanks!