Outlives requirements are not implied in the return type of async fn
, and generally for RPIT #130935
Open
Description
Split from #102682
The following doesn't compile:
trait MyTrait<T> {
async fn foo(&self) -> &T;
}
it gives the following:
error[E0311]: the parameter type `T` may not live long enough
--> <source>:2:5
|
2 | async fn foo(&self) -> &T;
| ^^^^^^^^^^^^^-^^^^^^^^^^^^
| | |
| | the parameter type `T` must be valid for the anonymous lifetime as defined here...
| ...so that the reference type `&T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
2 | async fn foo<'a>(&'a self) -> &'a T where T: 'a;
| ++++ ++ ++ +++++++++++
of course, a normal function is fine. We just don't imply that T: '_
here because it lowers to impl Future<Output = &'_ T>
Metadata
Assignees
Labels
Area: Async & AwaitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: Implied bounds / inferred outlives-boundsAsync-await issues that have been triaged during a working group meeting.Category: This is a bug.Relevant to the types team, which will review and decide on the PR/issue.