-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
handle elision in async fn correctly #63499
Merged
bors
merged 10 commits into
rust-lang:master
from
nikomatsakis:issuee-63388-async-fn-elision-self-mut-self
Aug 14, 2019
+2,067
−125
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
43a2cbd
lifetime elision: add conforming-to-fn tests.
Centril a694782
lifetime elision: add non-conforming-to-fn tests.
Centril d9294a2
lifetime elision: document conformance of 'async fn' to 'fn'.
Centril f395787
Add async version of self_lifetime.rs test.
Centril 5ce8f7a
Add async versions of arbitrary_self_types_pin_lifetime tests.
Centril 03e7b96
revamp how we handle elision in async fn
nikomatsakis 948739f
revamp comment
nikomatsakis ad214fe
fix README.md
nikomatsakis d7c7c52
bless tests
nikomatsakis 18d69c8
bless tests with compare-mode=nll
nikomatsakis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty clever and probably deserves a comment-- that
in_scope_lifetimes
contains all the non-elided lifetime names in scope, andlifetimes_to_define
says how many lifetimes we have been paired withCreateParameter
, so the lastlifetime_params.len() - (in_scope_lifetimes + lifetimes_to_define)
elements oflifetime_params
are all elided lifetimes. Obviously the way I just worded it is probably even more confusing than just reading the code, but I think some explanation would be helpful.