-
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
Always create elided lifetime parameters for functions #97720
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
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
21 changes: 21 additions & 0 deletions
21
src/test/ui/suggestions/impl-trait-missing-lifetime-gated.rs
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,21 @@ | ||
// edition:2021 | ||
// gate-test-anonymous_lifetime_in_impl_trait | ||
// Verify the behaviour of `feature(anonymous_lifetime_in_impl_trait)`. | ||
|
||
fn f(_: impl Iterator<Item = &'_ ()>) {} | ||
//~^ ERROR anonymous lifetimes in `impl Trait` are unstable | ||
|
||
fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
//~^ ERROR anonymous lifetimes in `impl Trait` are unstable | ||
//~| ERROR missing lifetime specifier | ||
|
||
// Anonymous lifetimes in async fn are already allowed. | ||
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`. | ||
async fn h(_: impl Iterator<Item = &'_ ()>) {} | ||
|
||
// Anonymous lifetimes in async fn are already allowed. | ||
// But that lifetime does not participate in resolution. | ||
async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
//~^ ERROR missing lifetime specifier | ||
|
||
fn main() {} |
44 changes: 44 additions & 0 deletions
44
src/test/ui/suggestions/impl-trait-missing-lifetime-gated.stderr
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,44 @@ | ||
error[E0658]: anonymous lifetimes in `impl Trait` are unstable | ||
--> $DIR/impl-trait-missing-lifetime-gated.rs:5:31 | ||
| | ||
LL | fn f(_: impl Iterator<Item = &'_ ()>) {} | ||
| ^^ | ||
| | ||
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:50 | ||
| | ||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
| ^^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments | ||
help: consider using the `'static` lifetime | ||
| | ||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() } | ||
| ~~~~~~~ | ||
|
||
error[E0658]: anonymous lifetimes in `impl Trait` are unstable | ||
--> $DIR/impl-trait-missing-lifetime-gated.rs:8:31 | ||
| | ||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
| ^^ | ||
| | ||
= help: add `#![feature(anonymous_lifetime_in_impl_trait)]` to the crate attributes to enable | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/impl-trait-missing-lifetime-gated.rs:18:56 | ||
| | ||
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
| ^^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments | ||
help: consider using the `'static` lifetime | ||
| | ||
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() } | ||
| ~~~~~~~ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
Some errors have detailed explanations: E0106, E0658. | ||
For more information about an 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 |
---|---|---|
@@ -1,2 +1,19 @@ | ||
fn f(_: impl Iterator<Item = &'_ ()>) {} //~ ERROR missing lifetime specifier | ||
// edition:2021 | ||
|
||
#![feature(anonymous_lifetime_in_impl_trait)] | ||
|
||
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`. | ||
fn f(_: impl Iterator<Item = &'_ ()>) {} | ||
|
||
// But that lifetime does not participate in resolution. | ||
fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
//~^ ERROR missing lifetime specifier | ||
|
||
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`. | ||
async fn h(_: impl Iterator<Item = &'_ ()>) {} | ||
|
||
// But that lifetime does not participate in resolution. | ||
async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
//~^ ERROR missing lifetime specifier | ||
|
||
fn main() {} |
27 changes: 20 additions & 7 deletions
27
src/test/ui/suggestions/impl-trait-missing-lifetime.stderr
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 |
---|---|---|
@@ -1,14 +1,27 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/impl-trait-missing-lifetime.rs:1:31 | ||
--> $DIR/impl-trait-missing-lifetime.rs:9:50 | ||
| | ||
LL | fn f(_: impl Iterator<Item = &'_ ()>) {} | ||
| ^^ expected named lifetime parameter | ||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
| ^^ expected named lifetime parameter | ||
| | ||
help: consider introducing a named lifetime parameter | ||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments | ||
help: consider using the `'static` lifetime | ||
| | ||
LL | fn f<'a>(_: impl Iterator<Item = &'a ()>) {} | ||
| ++++ ~~ | ||
LL | fn g(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() } | ||
| ~~~~~~~ | ||
|
||
error: aborting due to previous error | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/impl-trait-missing-lifetime.rs:16:56 | ||
| | ||
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() } | ||
| ^^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments | ||
help: consider using the `'static` lifetime | ||
| | ||
LL | async fn i(x: impl Iterator<Item = &'_ ()>) -> Option<&'static ()> { x.next() } | ||
| ~~~~~~~ | ||
|
||
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
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
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
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.
Or 1.64.0?