You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Outlives requirements are not implied in the return type of async fn, and generally for RPIT #130935
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>
changed the title [-]Outlives requirements are not implied in AFIT and RPITIT[/-][+]Outlives requirements are not implied in the return type of `async fn`, and generally for RPIT[/+]on Sep 27, 2024
I've edited the PR title to reflect its more general nature. This is because we don't walk into RPIT's projections to gather outlives constraints, i.e. we don't deduce any implied outlives bounds from impl Future<Output = &'a T>.
I'm not certain this is fixable in general. Deducing outlives from the return type of a function is only really doable because the implementation of the body serves as the witness of the outlive's validity, but this is obviously not true for all associated types, just the ones that are "output"-like.
Activity
compiler-errors commentedon Sep 27, 2024
I thought I mentioned in the issue that this has nothing to do with AFIT or RPITIT? This can be observed on regular RPIT and async fn:
[-]Outlives requirements are not implied in AFIT and RPITIT[/-][+]Outlives requirements are not implied in the return type of `async fn`, and generally for RPIT[/+]compiler-errors commentedon Sep 27, 2024
I've edited the PR title to reflect its more general nature. This is because we don't walk into RPIT's projections to gather outlives constraints, i.e. we don't deduce any implied outlives bounds from
impl Future<Output = &'a T>.I'm not certain this is fixable in general. Deducing outlives from the return type of a function is only really doable because the implementation of the body serves as the witness of the outlive's validity, but this is obviously not true for all associated types, just the ones that are "output"-like.