Skip to content

Commit 2ea2bb4

Browse files
committed
report pat no field error no recoverd struct variant
1 parent 382148d commit 2ea2bb4

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

compiler/rustc_hir_typeck/src/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15301530
.filter(|(_, ident)| !used_fields.contains_key(ident))
15311531
.collect::<Vec<_>>();
15321532

1533-
let inexistent_fields_err = if !(inexistent_fields.is_empty() || variant.is_recovered())
1533+
let inexistent_fields_err = if !inexistent_fields.is_empty()
15341534
&& !inexistent_fields.iter().any(|field| field.ident.name == kw::Underscore)
15351535
{
15361536
Some(self.error_inexistent_fields(

tests/ui/parser/recovered-struct-variant.stderr

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ LL | A { a, b: usize }
66
| |
77
| while parsing this struct
88

9-
error: aborting due to 1 previous error
9+
error[E0026]: variant `Foo::A` does not have fields named `a`, `b`
10+
--> $DIR/recovered-struct-variant.rs:11:17
11+
|
12+
LL | Foo::A {a, b} => {}
13+
| ^ ^ variant `Foo::A` does not have these fields
14+
15+
error: aborting due to 2 previous errors
1016

17+
For more information about this error, try `rustc --explain E0026`.

tests/ui/pattern/issue-66270-pat-struct-parser-recovery.stderr

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,12 @@ LL | struct Bug {
66
LL | incorrect_field: 0,
77
| ^ expected type
88

9-
error: aborting due to 1 previous error
9+
error[E0026]: struct `Bug` does not have a field named `any_field`
10+
--> $DIR/issue-66270-pat-struct-parser-recovery.rs:12:9
11+
|
12+
LL | any_field: Empty {},
13+
| ^^^^^^^^^ struct `Bug` does not have this field
14+
15+
error: aborting due to 2 previous errors
1016

17+
For more information about this error, try `rustc --explain E0026`.

0 commit comments

Comments
 (0)