Skip to content

Commit 20768d8

Browse files
committed
fix(thir): Include NoneWithError in enum struct tail assertion
1 parent d956393 commit 20768d8

3 files changed

Lines changed: 40 additions & 8 deletions

File tree

compiler/rustc_mir_build/src/thir/cx/expr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ impl<'tcx> ThirBuildCx<'tcx> {
645645
base,
646646
hir::StructTailExpr::None
647647
| hir::StructTailExpr::DefaultFields(_)
648+
| hir::StructTailExpr::NoneWithError(_)
648649
));
649650

650651
let index = adt.variant_index_with_id(variant_id);

tests/ui/structs/syntax-error-not-missing-field.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
struct Foo { a: isize, b: isize }
88

9+
enum Bar {
10+
Baz { a: isize, b: isize },
11+
}
12+
913
fn make_a() -> isize { 1234 }
1014

1115
fn expr_wrong_separator() {
@@ -35,4 +39,12 @@ fn pat_missing_separator(Foo { a b }: Foo) { //~ ERROR expected `,`
3539
fn pat_rest_trailing_comma(Foo { a, .., }: Foo) { //~ ERROR expected `}`, found `,`
3640
}
3741

42+
fn enum_expr_wrong_separator() {
43+
let e = Bar::Baz { a: make_a(); b: 2 }; //~ ERROR found `;`
44+
}
45+
46+
fn enum_expr_missing_separator() {
47+
let e = Bar::Baz { a: make_a() b: 2 }; //~ ERROR found `b`
48+
}
49+
3850
fn main() {}

tests/ui/structs/syntax-error-not-missing-field.stderr

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
2-
--> $DIR/syntax-error-not-missing-field.rs:12:30
2+
--> $DIR/syntax-error-not-missing-field.rs:16:30
33
|
44
LL | let f = Foo { a: make_a(); b: 2 };
55
| --- ^
@@ -9,7 +9,7 @@ LL | let f = Foo { a: make_a(); b: 2 };
99
| while parsing this struct
1010

1111
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `b`
12-
--> $DIR/syntax-error-not-missing-field.rs:16:31
12+
--> $DIR/syntax-error-not-missing-field.rs:20:31
1313
|
1414
LL | let f = Foo { a: make_a() b: 2 };
1515
| --- -^ expected one of `,`, `.`, `?`, `}`, or an operator
@@ -18,7 +18,7 @@ LL | let f = Foo { a: make_a() b: 2 };
1818
| while parsing this struct
1919

2020
error: cannot use a comma after the base struct
21-
--> $DIR/syntax-error-not-missing-field.rs:20:32
21+
--> $DIR/syntax-error-not-missing-field.rs:24:32
2222
|
2323
LL | let f = Foo { a: make_a(), ..todo!(), };
2424
| ^^^^^^^^^
@@ -31,7 +31,7 @@ LL + let f = Foo { a: make_a(), ..todo!() };
3131
|
3232

3333
error: expected one of `,`, `:`, or `}`, found `(`
34-
--> $DIR/syntax-error-not-missing-field.rs:24:25
34+
--> $DIR/syntax-error-not-missing-field.rs:28:25
3535
|
3636
LL | let f = Foo { make_a(), b: 2, };
3737
| --- ------^ expected one of `,`, `:`, or `}`
@@ -45,23 +45,23 @@ LL | let f = Foo { make_a: make_a(), b: 2, };
4545
| +++++++
4646

4747
error: expected `,`
48-
--> $DIR/syntax-error-not-missing-field.rs:27:31
48+
--> $DIR/syntax-error-not-missing-field.rs:31:31
4949
|
5050
LL | fn pat_wrong_separator(Foo { a; b }: Foo) {
5151
| --- ^
5252
| |
5353
| while parsing the fields for this pattern
5454

5555
error: expected `,`
56-
--> $DIR/syntax-error-not-missing-field.rs:31:34
56+
--> $DIR/syntax-error-not-missing-field.rs:35:34
5757
|
5858
LL | fn pat_missing_separator(Foo { a b }: Foo) {
5959
| --- ^
6060
| |
6161
| while parsing the fields for this pattern
6262

6363
error: expected `}`, found `,`
64-
--> $DIR/syntax-error-not-missing-field.rs:35:39
64+
--> $DIR/syntax-error-not-missing-field.rs:39:39
6565
|
6666
LL | fn pat_rest_trailing_comma(Foo { a, .., }: Foo) {
6767
| --^
@@ -70,5 +70,24 @@ LL | fn pat_rest_trailing_comma(Foo { a, .., }: Foo) {
7070
| | help: remove this comma
7171
| `..` must be at the end and cannot have a trailing comma
7272

73-
error: aborting due to 7 previous errors
73+
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `;`
74+
--> $DIR/syntax-error-not-missing-field.rs:43:35
75+
|
76+
LL | let e = Bar::Baz { a: make_a(); b: 2 };
77+
| -------- ^
78+
| | |
79+
| | expected one of `,`, `.`, `?`, `}`, or an operator
80+
| | help: try adding a comma: `,`
81+
| while parsing this struct
82+
83+
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `b`
84+
--> $DIR/syntax-error-not-missing-field.rs:47:36
85+
|
86+
LL | let e = Bar::Baz { a: make_a() b: 2 };
87+
| -------- -^ expected one of `,`, `.`, `?`, `}`, or an operator
88+
| | |
89+
| | help: try adding a comma: `,`
90+
| while parsing this struct
91+
92+
error: aborting due to 9 previous errors
7493

0 commit comments

Comments
 (0)