Auto merge of #91403 - cjgillot:inherit-async, r=oli-obk
Inherit lifetimes for async fn instead of duplicating them. The current desugaring of `async fn foo<'a>(&usize) -> &u8` is equivalent to ```rust fn foo<'a, '0>(&'0 usize) -> foo<'static, 'static>::Opaque<'a, '0, '_>; type foo<'_a, '_0>::Opaque<'a, '0, '1> = impl Future<Output = &'1 u8>; ``` following the RPIT model. Duplicating all the inherited lifetime parameters and setting the inherited version to `'static` makes lowering more complex and causes issues like #61949. This PR removes the duplication of inherited lifetimes to directly use ```rust fn foo<'a, '0>(&'0 usize) -> foo<'a, '0>::Opaque<'_>; type foo<'a, '0>::Opaque<'1> = impl Future<Output = &'1 u8>; ``` following the TAIT model. Fixes https://github.com/rust-lang/rust/issues/61949
This commit is contained in:
commit
3cfa4def7c
34 changed files with 227 additions and 281 deletions
|
@ -1,4 +1,4 @@
|
|||
`async fn`/`impl trait` return type cannot contain a projection
|
||||
`impl trait` return type cannot contain a projection
|
||||
or `Self` that references lifetimes from a parent scope.
|
||||
|
||||
Erroneous code example:
|
||||
|
@ -7,7 +7,7 @@ Erroneous code example:
|
|||
struct S<'a>(&'a i32);
|
||||
|
||||
impl<'a> S<'a> {
|
||||
async fn new(i: &'a i32) -> Self {
|
||||
fn new(i: &'a i32) -> impl Into<Self> {
|
||||
S(&22)
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ To fix this error we need to spell out `Self` to `S<'a>`:
|
|||
struct S<'a>(&'a i32);
|
||||
|
||||
impl<'a> S<'a> {
|
||||
async fn new(i: &'a i32) -> S<'a> {
|
||||
fn new(i: &'a i32) -> impl Into<S<'a>> {
|
||||
S(&22)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue