Skip to content

Commit

Permalink
Add tests for struct literals in if let/while let
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Aug 28, 2023
1 parent 7e02fd8 commit 56c17dc
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tests/ui/parser/struct-literal-in-if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
18 changes: 17 additions & 1 deletion tests/ui/parser/struct-literal-in-if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

5 changes: 5 additions & 0 deletions tests/ui/parser/struct-literal-in-while.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
18 changes: 17 additions & 1 deletion tests/ui/parser/struct-literal-in-while.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 56c17dc

Please sign in to comment.