-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.