Skip to content

Commit 56c17dc

Browse files
committed
Add tests for struct literals in if let/while let
1 parent 7e02fd8 commit 56c17dc

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Diff for: tests/ui/parser/struct-literal-in-if.rs

+5
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ fn main() {
1414
}.hi() {
1515
println!("yo");
1616
}
17+
if let true = Foo { //~ ERROR struct literals are not allowed here
18+
x: 3
19+
}.hi() {
20+
println!("yo");
21+
}
1722
}

Diff for: tests/ui/parser/struct-literal-in-if.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,21 @@ LL | x: 3
1414
LL ~ }).hi() {
1515
|
1616

17-
error: aborting due to previous error
17+
error: struct literals are not allowed here
18+
--> $DIR/struct-literal-in-if.rs:17:19
19+
|
20+
LL | if let true = Foo {
21+
| ___________________^
22+
LL | | x: 3
23+
LL | | }.hi() {
24+
| |_____^
25+
|
26+
help: surround the struct literal with parentheses
27+
|
28+
LL ~ if let true = (Foo {
29+
LL | x: 3
30+
LL ~ }).hi() {
31+
|
32+
33+
error: aborting due to 2 previous errors
1834

Diff for: tests/ui/parser/struct-literal-in-while.rs

+5
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ fn main() {
1414
}.hi() {
1515
println!("yo");
1616
}
17+
while let true = Foo { //~ ERROR struct literals are not allowed here
18+
x: 3
19+
}.hi() {
20+
println!("yo");
21+
}
1722
}

Diff for: tests/ui/parser/struct-literal-in-while.stderr

+17-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,21 @@ LL | x: 3
1414
LL ~ }).hi() {
1515
|
1616

17-
error: aborting due to previous error
17+
error: struct literals are not allowed here
18+
--> $DIR/struct-literal-in-while.rs:17:22
19+
|
20+
LL | while let true = Foo {
21+
| ______________________^
22+
LL | | x: 3
23+
LL | | }.hi() {
24+
| |_____^
25+
|
26+
help: surround the struct literal with parentheses
27+
|
28+
LL ~ while let true = (Foo {
29+
LL | x: 3
30+
LL ~ }).hi() {
31+
|
32+
33+
error: aborting due to 2 previous errors
1834

0 commit comments

Comments
 (0)