async fn
doesn't capture lifetimes of type parameters if other lifetimes are present
#55324
Labels
A-async-await
Area: Async & Await
A-lifetimes
Area: Lifetimes / regions
AsyncAwait-Polish
Async-await issues that are part of the "polish" area
This doesn't compile:
But it does compile if you replace the
&i32
with ani32
. This is becauseasync fn foo<T>() -> R
desugars to-> impl Future<Output = R>
, butasync fn foo<T>(x: &i32) -> R
desugars to-> impl Future<Output = R> + '_
. SinceT
doesn't outlive the elided lifetime, it fails to compile. We need instead to capture the minimum lifetime ofT
and'_
. Note that this is similar to the issue whereasync fn
cannot have multiple different named lifetimes because there's not a way to express the desugared "minimum of all lifetimes" in the-> impl Trait
return type.cc @withoutboats who originally reported this on discord.
The text was updated successfully, but these errors were encountered: