-
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
Parser: Suggest Placing the Return Type After Function Parameters #127350
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
5 changes: 5 additions & 0 deletions
5
tests/ui/parser/issues/misplaced-return-type-complex-type-issue-126311.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,5 @@ | ||
fn foo<T>() where T: Default -> impl Default + 'static {} | ||
//~^ ERROR return type should be specified after the function parameters | ||
//~| HELP place the return type after the function parameters | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
tests/ui/parser/issues/misplaced-return-type-complex-type-issue-126311.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,14 @@ | ||
error: return type should be specified after the function parameters | ||
--> $DIR/misplaced-return-type-complex-type-issue-126311.rs:1:30 | ||
| | ||
LL | fn foo<T>() where T: Default -> impl Default + 'static {} | ||
| ^^ expected one of `(`, `+`, `,`, `::`, `<`, or `{` | ||
| | ||
help: place the return type after the function parameters | ||
| | ||
LL - fn foo<T>() where T: Default -> impl Default + 'static {} | ||
LL + fn foo<T>() -> impl Default + 'static where T: Default {} | ||
| | ||
|
||
error: aborting due to 1 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,5 @@ | ||
fn foo<T>() where T: Default -> u8 {} | ||
//~^ ERROR return type should be specified after the function parameters | ||
//~| HELP place the return type after the function parameters | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
tests/ui/parser/issues/misplaced-return-type-issue-126311.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,14 @@ | ||
error: return type should be specified after the function parameters | ||
--> $DIR/misplaced-return-type-issue-126311.rs:1:30 | ||
| | ||
LL | fn foo<T>() where T: Default -> u8 {} | ||
| ^^ expected one of `(`, `+`, `,`, `::`, `<`, or `{` | ||
| | ||
help: place the return type after the function parameters | ||
| | ||
LL - fn foo<T>() where T: Default -> u8 {} | ||
LL + fn foo<T>() -> u8 where T: Default {} | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
11 changes: 11 additions & 0 deletions
11
tests/ui/parser/issues/misplaced-return-type-where-in-next-line-issue-126311.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,11 @@ | ||
fn foo<T, K>() | ||
//~^ HELP place the return type after the function parameters | ||
where | ||
T: Default, | ||
K: Clone, -> Result<u8, String> | ||
//~^ ERROR return type should be specified after the function parameters | ||
{ | ||
Ok(0) | ||
} | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/parser/issues/misplaced-return-type-where-in-next-line-issue-126311.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,17 @@ | ||
error: return type should be specified after the function parameters | ||
--> $DIR/misplaced-return-type-where-in-next-line-issue-126311.rs:5:15 | ||
| | ||
LL | K: Clone, -> Result<u8, String> | ||
| ^^ expected one of `{`, lifetime, or type | ||
| | ||
help: place the return type after the function parameters | ||
| | ||
LL ~ fn foo<T, K>() -> Result<u8, String> | ||
LL | | ||
LL | where | ||
LL | T: Default, | ||
LL ~ K: Clone, | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
6 changes: 6 additions & 0 deletions
6
tests/ui/parser/issues/misplaced-return-type-without-type-issue-126311.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,6 @@ | ||
fn foo<T>() where T: Default -> { | ||
//~^ ERROR expected one of `(`, `+`, `,`, `::`, `<`, or `{`, found `->` | ||
0 | ||
} | ||
|
||
fn main() {} |
8 changes: 8 additions & 0 deletions
8
tests/ui/parser/issues/misplaced-return-type-without-type-issue-126311.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,8 @@ | ||
error: expected one of `(`, `+`, `,`, `::`, `<`, or `{`, found `->` | ||
--> $DIR/misplaced-return-type-without-type-issue-126311.rs:1:30 | ||
| | ||
LL | fn foo<T>() where T: Default -> { | ||
| ^^ expected one of `(`, `+`, `,`, `::`, `<`, or `{` | ||
|
||
error: aborting due to 1 previous error | ||
|
4 changes: 4 additions & 0 deletions
4
tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.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,4 @@ | ||
fn bar<T>() -> u8 -> u64 {} | ||
//~^ ERROR expected one of `!`, `(`, `+`, `::`, `<`, `where`, or `{`, found `->` | ||
|
||
fn main() {} |
8 changes: 8 additions & 0 deletions
8
tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.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,8 @@ | ||
error: expected one of `!`, `(`, `+`, `::`, `<`, `where`, or `{`, found `->` | ||
--> $DIR/misplaced-return-type-without-where-issue-126311.rs:1:19 | ||
| | ||
LL | fn bar<T>() -> u8 -> u64 {} | ||
| ^^ expected one of 7 possible tokens | ||
|
||
error: aborting due to 1 previous error | ||
|
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.
what's the harm of always passing in that span?
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.
Checking if a where clause exists makes sure we don't incorrectly suggest to place the second return type after function parameters for code like
fn fun<T>() -> u8 -> u8 {}
.I've added that as a test in https://github.com/rust-lang/rust/blob/d14e2818e8d5e9d65f464517d1a88272b626629e/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.stderr.