Do not complain about unmentioned fields in recovered patterns
When the parser has to recover from malformed code in a pattern, do not complain about missing fields.
This commit is contained in:
parent
7486b9c208
commit
6cd6759cfc
7 changed files with 5 additions and 28 deletions
|
@ -4698,7 +4698,7 @@ impl<'a> Parser<'a> {
|
||||||
let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
|
let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
|
||||||
e.emit();
|
e.emit();
|
||||||
self.recover_stmt();
|
self.recover_stmt();
|
||||||
(vec![], false)
|
(vec![], true)
|
||||||
});
|
});
|
||||||
self.bump();
|
self.bump();
|
||||||
pat = PatKind::Struct(path, fields, etc);
|
pat = PatKind::Struct(path, fields, etc);
|
||||||
|
|
|
@ -2,7 +2,6 @@ fn main() {
|
||||||
struct Foo { x: isize }
|
struct Foo { x: isize }
|
||||||
match (Foo { x: 10 }) {
|
match (Foo { x: 10 }) {
|
||||||
Foo { ref x: ref x } => {}, //~ ERROR expected `,`
|
Foo { ref x: ref x } => {}, //~ ERROR expected `,`
|
||||||
//~| ERROR pattern does not mention field `x`
|
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,5 @@ error: expected `,`
|
||||||
LL | Foo { ref x: ref x } => {},
|
LL | Foo { ref x: ref x } => {},
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error[E0027]: pattern does not mention field `x`
|
error: aborting due to previous error
|
||||||
--> $DIR/bind-struct-early-modifiers.rs:4:9
|
|
||||||
|
|
|
||||||
LL | Foo { ref x: ref x } => {},
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ missing field `x`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0027`.
|
|
||||||
|
|
|
@ -4,5 +4,4 @@ fn a() -> A { panic!() }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let A { , } = a(); //~ ERROR expected ident
|
let A { , } = a(); //~ ERROR expected ident
|
||||||
//~| ERROR pattern does not mention field `foo`
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,5 @@ error: expected identifier, found `,`
|
||||||
LL | let A { , } = a();
|
LL | let A { , } = a();
|
||||||
| ^ expected identifier
|
| ^ expected identifier
|
||||||
|
|
||||||
error[E0027]: pattern does not mention field `foo`
|
error: aborting due to previous error
|
||||||
--> $DIR/issue-10392.rs:6:9
|
|
||||||
|
|
|
||||||
LL | let A { , } = a();
|
|
||||||
| ^^^^^^^ missing field `foo`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0027`.
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ fn main() {
|
||||||
let thing = MyStruct { s1: None };
|
let thing = MyStruct { s1: None };
|
||||||
|
|
||||||
match thing {
|
match thing {
|
||||||
MyStruct { .., Some(_) } => {}, //~ ERROR pattern does not mention field `s1`
|
MyStruct { .., Some(_) } => {},
|
||||||
//~^ ERROR expected `,`
|
//~^ ERROR expected `,`
|
||||||
//~| ERROR expected `}`, found `,`
|
//~| ERROR expected `}`, found `,`
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -13,12 +13,5 @@ error: expected `,`
|
||||||
LL | MyStruct { .., Some(_) } => {},
|
LL | MyStruct { .., Some(_) } => {},
|
||||||
| ^^^^
|
| ^^^^
|
||||||
|
|
||||||
error[E0027]: pattern does not mention field `s1`
|
error: aborting due to 2 previous errors
|
||||||
--> $DIR/issue-54379.rs:9:9
|
|
||||||
|
|
|
||||||
LL | MyStruct { .., Some(_) } => {},
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing field `s1`
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0027`.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue