Outlives requirements are not implied in the return type of `async fn`, and generally for RPIT
Open
Nobody has claimed this yet.
A-async-await
A-impl-trait
A-implied-bounds
AsyncAwait-Triaged
C-bug
T-types
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the async trait method example from the issue and comparing it with the equivalent normal function, which compiles. Investigate how async fn lowers to impl Future<Output = &'_ T> and how RPIT handles implied outlives requirements. Done means the example compiles without the explicit lifetime bound and has regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100