diff options
| author | León Orell Valerian Liehr <liehr.exchange@gmx.net> | 2023-01-06 17:47:21 +0100 |
|---|---|---|
| committer | León Orell Valerian Liehr <liehr.exchange@gmx.net> | 2023-01-11 17:54:48 +0100 |
| commit | 70ddde76dfbb03909c565b329f86e49de1f767cc (patch) | |
| tree | 70f3b7a49c33c052749413d30547e52dd913a7b2 /tests/ui/parser | |
| parent | b22c152958eade17a71d899b29a2d39bcc77aa48 (diff) | |
| download | rust-70ddde76dfbb03909c565b329f86e49de1f767cc.tar.gz rust-70ddde76dfbb03909c565b329f86e49de1f767cc.zip | |
parser: recover from where clauses placed before tuple struct bodies
Diffstat (limited to 'tests/ui/parser')
7 files changed, 117 insertions, 4 deletions
diff --git a/tests/ui/parser/issues/issue-17904.rs b/tests/ui/parser/issues/issue-17904.rs index 7d6a54f4be1..020fb41c227 100644 --- a/tests/ui/parser/issues/issue-17904.rs +++ b/tests/ui/parser/issues/issue-17904.rs @@ -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() {} diff --git a/tests/ui/parser/issues/issue-17904.stderr b/tests/ui/parser/issues/issue-17904.stderr index a3cac676189..aa343975dca 100644 --- a/tests/ui/parser/issues/issue-17904.stderr +++ b/tests/ui/parser/issues/issue-17904.stderr @@ -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 diff --git a/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.fixed b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.fixed new file mode 100644 index 00000000000..227c40e97c0 --- /dev/null +++ b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.fixed @@ -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() {} diff --git a/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.rs b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.rs new file mode 100644 index 00000000000..3699e6fe572 --- /dev/null +++ b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.rs @@ -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() {} diff --git a/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.stderr b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.stderr new file mode 100644 index 00000000000..18aa5fadb6b --- /dev/null +++ b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-0.stderr @@ -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 + diff --git a/tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.rs b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.rs new file mode 100644 index 00000000000..f515ae81e51 --- /dev/null +++ b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.rs @@ -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>` diff --git a/tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.stderr b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.stderr new file mode 100644 index 00000000000..2219c2a7316 --- /dev/null +++ b/tests/ui/parser/recover-where-clause-before-tuple-struct-body-1.stderr @@ -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 + |
