-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #106537 - fmease:recover-where-clause-before-tuple-stru…
…ct-body, r=estebank Recover from where clauses placed before tuple struct bodies Open to any suggestions regarding the phrasing of the diagnostic. Fixes #100790. `@rustbot` label A-diagnostics r? diagnostics
- Loading branch information
Showing
11 changed files
with
266 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// compile-flags: -Zparse-only | ||
|
||
struct Baz<U> where U: Eq(U); //This is parsed as the new Fn* style parenthesis syntax. | ||
struct Baz<U> where U: Eq(U) -> R; // Notice this parses as well. | ||
struct Baz<U>(U) where U: Eq; // This rightfully signals no error as well. | ||
struct Foo<T> where T: Copy, (T); //~ ERROR expected one of `:`, `==`, or `=`, found `;` | ||
struct Foo<T> where T: Copy, (T); //~ ERROR where clauses are not allowed before tuple struct bodies | ||
|
||
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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
error: expected one of `:`, `==`, or `=`, found `;` | ||
--> $DIR/issue-17904.rs:4:33 | ||
error: where clauses are not allowed before tuple struct bodies | ||
--> $DIR/issue-17904.rs:6:15 | ||
| | ||
LL | struct Foo<T> where T: Copy, (T); | ||
| ^ expected one of `:`, `==`, or `=` | ||
| --- ^^^^^^^^^^^^^^ --- the struct body | ||
| | | | ||
| | unexpected where clause | ||
| while parsing this tuple struct | ||
| | ||
help: move the body before the where clause | ||
| | ||
LL - struct Foo<T> where T: Copy, (T); | ||
LL + struct Foo<T>(T) where T: Copy; | ||
| | ||
|
||
error: aborting due to previous error | ||
|
15 changes: 15 additions & 0 deletions
15
tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.fixed
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,15 @@ | ||
// Regression test for issues #100790 and #106439. | ||
// run-rustfix | ||
|
||
pub struct Example(usize) | ||
where | ||
(): Sized; | ||
//~^^^ ERROR where clauses are not allowed before tuple struct bodies | ||
|
||
struct _Demo(pub usize, usize) | ||
where | ||
(): Sized, | ||
String: Clone; | ||
//~^^^^ ERROR where clauses are not allowed before tuple struct bodies | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.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,17 @@ | ||
// Regression test for issues #100790 and #106439. | ||
// run-rustfix | ||
|
||
pub struct Example | ||
where | ||
(): Sized, | ||
(usize); | ||
//~^^^ ERROR where clauses are not allowed before tuple struct bodies | ||
|
||
struct _Demo | ||
where | ||
(): Sized, | ||
String: Clone, | ||
(pub usize, usize); | ||
//~^^^^ ERROR where clauses are not allowed before tuple struct bodies | ||
|
||
fn main() {} |
40 changes: 40 additions & 0 deletions
40
tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.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,40 @@ | ||
error: where clauses are not allowed before tuple struct bodies | ||
--> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:5:1 | ||
| | ||
LL | pub struct Example | ||
| ------- while parsing this tuple struct | ||
LL | / where | ||
LL | | (): Sized, | ||
| |______________^ unexpected where clause | ||
LL | (usize); | ||
| ------- the struct body | ||
| | ||
help: move the body before the where clause | ||
| | ||
LL ~ pub struct Example(usize) | ||
LL | where | ||
LL ~ (): Sized; | ||
| | ||
|
||
error: where clauses are not allowed before tuple struct bodies | ||
--> $DIR/recover-where-clause-before-tuple-struct-body-0.rs:11:1 | ||
| | ||
LL | struct _Demo | ||
| ----- while parsing this tuple struct | ||
LL | / where | ||
LL | | (): Sized, | ||
LL | | String: Clone, | ||
| |__________________^ unexpected where clause | ||
LL | (pub usize, usize); | ||
| ------------------ the struct body | ||
| | ||
help: move the body before the where clause | ||
| | ||
LL ~ struct _Demo(pub usize, usize) | ||
LL | where | ||
LL | (): Sized, | ||
LL ~ String: Clone; | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
7 changes: 7 additions & 0 deletions
7
tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.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,7 @@ | ||
// Regression test for issues #100790 and #106439. | ||
|
||
// Make sure that we still show a helpful error message even if the trailing semicolon is missing. | ||
|
||
struct Foo<T> where T: MyTrait, (T) | ||
//~^ ERROR where clauses are not allowed before tuple struct bodies | ||
//~| ERROR expected `;`, found `<eof>` |
23 changes: 23 additions & 0 deletions
23
tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.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,23 @@ | ||
error: where clauses are not allowed before tuple struct bodies | ||
--> $DIR/recover-where-clause-before-tuple-struct-body-1.rs:5:15 | ||
| | ||
LL | struct Foo<T> where T: MyTrait, (T) | ||
| --- ^^^^^^^^^^^^^^^^^ --- the struct body | ||
| | | | ||
| | unexpected where clause | ||
| while parsing this tuple struct | ||
| | ||
help: move the body before the where clause | ||
| | ||
LL - struct Foo<T> where T: MyTrait, (T) | ||
LL + struct Foo<T>(T) where T: MyTrait | ||
| | ||
|
||
error: expected `;`, found `<eof>` | ||
--> $DIR/recover-where-clause-before-tuple-struct-body-1.rs:5:35 | ||
| | ||
LL | struct Foo<T> where T: MyTrait, (T) | ||
| ^ expected `;` | ||
|
||
error: aborting due to 2 previous errors | ||
|