-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revamp how we handle elision in async fn
We now always make fresh lifetimne parameters for all elided lifetimes, whether they are in the inputs or outputs. But then we generate `'_` in the case of elided lifetimes from the outputs. Example: ```rust async fn foo<'a>(x: &'a u32) -> &u32 { .. } ``` becomes ```rust type Foo<'a, 'b> = impl Future<Output = &'b u32>; fn foo<'a>(x: &'a u32) -> Foo<'a, '_> ```
- Loading branch information
1 parent
5ce8f7a
commit 03e7b96
Showing
30 changed files
with
383 additions
and
1,637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
struct Xyz { | ||
a: u64, | ||
} | ||
|
||
trait Foo {} | ||
|
||
impl Xyz { | ||
async fn do_sth<'a>( | ||
&'a self, foo: &dyn Foo | ||
) -> &dyn Foo //~ ERROR lifetime mismatch | ||
{ | ||
foo | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0623]: lifetime mismatch | ||
--> $DIR/issue-63388-1.rs:14:10 | ||
| | ||
LL | &'a self, foo: &dyn Foo | ||
| -------- this parameter and the return type are declared with different lifetimes... | ||
LL | ) -> &dyn Foo | ||
| ^^^^^^^^ | ||
| | | ||
| ...but data from `foo` is returned here | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
struct Xyz { | ||
a: u64, | ||
} | ||
|
||
trait Foo {} | ||
|
||
impl Xyz { | ||
async fn do_sth<'a>( | ||
foo: &dyn Foo, bar: &'a dyn Foo //~ ERROR cannot infer | ||
) -> &dyn Foo //~ ERROR missing lifetime specifier | ||
{ | ||
foo | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/issue-63388-2.rs:14:10 | ||
| | ||
LL | ) -> &dyn Foo | ||
| ^ help: consider using the named lifetime: `&'a` | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `foo` or `bar` | ||
|
||
error: cannot infer an appropriate lifetime | ||
--> $DIR/issue-63388-2.rs:13:9 | ||
| | ||
LL | foo: &dyn Foo, bar: &'a dyn Foo | ||
| ^^^ ...but this borrow... | ||
LL | ) -> &dyn Foo | ||
| -------- this return type evaluates to the `'static` lifetime... | ||
| | ||
note: ...can't outlive the lifetime '_ as defined on the method body at 13:14 | ||
--> $DIR/issue-63388-2.rs:13:14 | ||
| | ||
LL | foo: &dyn Foo, bar: &'a dyn Foo | ||
| ^ | ||
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime '_ as defined on the method body at 13:14 | ||
| | ||
LL | ) -> &dyn Foo + '_ | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0106`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// edition:2018 | ||
// check-pass | ||
|
||
#![feature(async_await)] | ||
|
||
struct Xyz { | ||
a: u64, | ||
} | ||
|
||
trait Foo {} | ||
|
||
impl Xyz { | ||
async fn do_sth( | ||
&self, foo: &dyn Foo | ||
) { | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// check-pass | ||
// edition:2018 | ||
|
||
#![feature(async_await)] | ||
|
||
struct A; | ||
|
||
impl A { | ||
async fn foo(&self, f: &u32) -> &A { self } | ||
} | ||
|
||
fn main() { } |
Oops, something went wrong.