-
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
Merged
Changes from all commits
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,24 @@ | ||
error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds | ||
--> $DIR/issue-63388-1.rs:14:10 | ||
| | ||
LL | ) -> &dyn Foo | ||
| ^^^^^^^^ | ||
| | ||
= note: hidden type `impl std::future::Future` captures lifetime '_#27r | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-63388-1.rs:15:5 | ||
| | ||
LL | async fn do_sth<'a>( | ||
| -- lifetime `'a` defined here | ||
LL | &'a self, foo: &dyn Foo | ||
| - lifetime `'_` defined here | ||
LL | ) -> &dyn Foo | ||
LL | / { | ||
LL | | foo | ||
LL | | } | ||
| |_____^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'_` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0700`. |
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,11 @@ | ||
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: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0106`. |
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.