diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2023-08-28 10:30:48 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2023-08-28 10:30:48 +0100 |
| commit | 56c17dc280c32112a9adf2cc69c845aa90d18dc4 (patch) | |
| tree | b2ba631b3012e7f57c71f769105eb2b797aed446 | |
| parent | 7e02fd825198e9a958bac085506890a895498aa0 (diff) | |
| download | rust-56c17dc280c32112a9adf2cc69c845aa90d18dc4.tar.gz rust-56c17dc280c32112a9adf2cc69c845aa90d18dc4.zip | |
Add tests for struct literals in if let/while let
| -rw-r--r-- | tests/ui/parser/struct-literal-in-if.rs | 5 | ||||
| -rw-r--r-- | tests/ui/parser/struct-literal-in-if.stderr | 18 | ||||
| -rw-r--r-- | tests/ui/parser/struct-literal-in-while.rs | 5 | ||||
| -rw-r--r-- | tests/ui/parser/struct-literal-in-while.stderr | 18 |
4 files changed, 44 insertions, 2 deletions
diff --git a/tests/ui/parser/struct-literal-in-if.rs b/tests/ui/parser/struct-literal-in-if.rs index 2ce2c8f1899..c4a253c3da2 100644 --- a/tests/ui/parser/struct-literal-in-if.rs +++ b/tests/ui/parser/struct-literal-in-if.rs @@ -14,4 +14,9 @@ fn main() { }.hi() { println!("yo"); } + if let true = Foo { //~ ERROR struct literals are not allowed here + x: 3 + }.hi() { + println!("yo"); + } } diff --git a/tests/ui/parser/struct-literal-in-if.stderr b/tests/ui/parser/struct-literal-in-if.stderr index b5a9864bbc4..8b72469fcf5 100644 --- a/tests/ui/parser/struct-literal-in-if.stderr +++ b/tests/ui/parser/struct-literal-in-if.stderr @@ -14,5 +14,21 @@ LL | x: 3 LL ~ }).hi() { | -error: aborting due to previous error +error: struct literals are not allowed here + --> $DIR/struct-literal-in-if.rs:17:19 + | +LL | if let true = Foo { + | ___________________^ +LL | | x: 3 +LL | | }.hi() { + | |_____^ + | +help: surround the struct literal with parentheses + | +LL ~ if let true = (Foo { +LL | x: 3 +LL ~ }).hi() { + | + +error: aborting due to 2 previous errors diff --git a/tests/ui/parser/struct-literal-in-while.rs b/tests/ui/parser/struct-literal-in-while.rs index 5000ce85b7f..86931f7888d 100644 --- a/tests/ui/parser/struct-literal-in-while.rs +++ b/tests/ui/parser/struct-literal-in-while.rs @@ -14,4 +14,9 @@ fn main() { }.hi() { println!("yo"); } + while let true = Foo { //~ ERROR struct literals are not allowed here + x: 3 + }.hi() { + println!("yo"); + } } diff --git a/tests/ui/parser/struct-literal-in-while.stderr b/tests/ui/parser/struct-literal-in-while.stderr index 17e9277e074..13d003608a1 100644 --- a/tests/ui/parser/struct-literal-in-while.stderr +++ b/tests/ui/parser/struct-literal-in-while.stderr @@ -14,5 +14,21 @@ LL | x: 3 LL ~ }).hi() { | -error: aborting due to previous error +error: struct literals are not allowed here + --> $DIR/struct-literal-in-while.rs:17:22 + | +LL | while let true = Foo { + | ______________________^ +LL | | x: 3 +LL | | }.hi() { + | |_____^ + | +help: surround the struct literal with parentheses + | +LL ~ while let true = (Foo { +LL | x: 3 +LL ~ }).hi() { + | + +error: aborting due to 2 previous errors |
