forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#127350 - veera-sivarajan:bugfix-126311, r=lcnr
Parser: Suggest Placing the Return Type After Function Parameters Fixes rust-lang#126311 This PR suggests placing the return type after the function parameters when it's misplaced after a `where` clause. This also tangentially improves diagnostics for cases like [this](https://github.com/veera-sivarajan/rust/blob/86d6f1312a77997ef994240e716288d61a343a6d/tests/ui/parser/issues/misplaced-return-type-without-where-issue-126311.rs#L1C1-L1C28) and adds doc comments for `parser::AllowPlus`.
- Loading branch information
Showing
16 changed files
with
215 additions
and
39 deletions.
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 | ||
|