-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
typeck: Prohibit RPIT types that inherit lifetimes #62849
Merged
bors
merged 1 commit into
rust-lang:master
from
davidtwco:prohibit-inheriting-lifetimes
Aug 14, 2019
+132
−6
Merged
Changes from all commits
Commits
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,28 @@ | ||
// ignore-tidy-linelength | ||
// edition:2018 | ||
#![feature(async_await)] | ||
|
||
// This test checks that `Self` is prohibited as a return type. See #61949 for context. | ||
|
||
pub struct Foo<'a> { | ||
pub bar: &'a i32, | ||
} | ||
|
||
impl<'a> Foo<'a> { | ||
pub async fn new(_bar: &'a i32) -> Self { | ||
//~^ ERROR `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope | ||
Foo { | ||
bar: &22 | ||
} | ||
} | ||
} | ||
|
||
async fn foo() { | ||
let x = { | ||
let bar = 22; | ||
Foo::new(&bar).await | ||
}; | ||
drop(x); | ||
} | ||
|
||
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,8 @@ | ||
error: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope | ||
--> $DIR/issue-61949-self-return-type.rs:12:40 | ||
| | ||
LL | pub async fn new(_bar: &'a i32) -> Self { | ||
davidtwco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ^^^^ | ||
|
||
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
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
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.
I wonder if we should try to give some clue for how to workaround this -- this is basically a rustc bug.
In the case of
Self
, the suggestion would be to write theSelf
type explicitly.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.
I've dug around for a bit and I've not been able to find a way to determine if the return type was originally
Self
from here. I'm happy to add a suggestion if anyone knows a way to determine this.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.
At minimum we could just -- for this particular issue -- give it an error code and direct them to some chapter in the async book where we explain in more depth (in the extended explanation). But we'd need a link first. Maybe we can just file a follow-up issue on the matter to improve diagnostics.