Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not complain about unmentioned fields in recovered patterns #59198

Merged
merged 1 commit into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4698,7 +4698,7 @@ impl<'a> Parser<'a> {
let (fields, etc) = self.parse_pat_fields().unwrap_or_else(|mut e| {
e.emit();
self.recover_stmt();
(vec![], false)
(vec![], true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing my understanding: this is getting assigned to the name etc; so, the mechanism here is that we're pretending that struct patterns that failed to parse have a .. so that we shouldn't emit additional errors about missing fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

});
self.bump();
pat = PatKind::Struct(path, fields, etc);
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/parser/bind-struct-early-modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ fn main() {
struct Foo { x: isize }
match (Foo { x: 10 }) {
Foo { ref x: ref x } => {}, //~ ERROR expected `,`
//~| ERROR pattern does not mention field `x`
_ => {}
}
}
9 changes: 1 addition & 8 deletions src/test/ui/parser/bind-struct-early-modifiers.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@ error: expected `,`
LL | Foo { ref x: ref x } => {},
| ^

error[E0027]: pattern does not mention field `x`
--> $DIR/bind-struct-early-modifiers.rs:4:9
|
LL | Foo { ref x: ref x } => {},
| ^^^^^^^^^^^^^^^^^^^^ missing field `x`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0027`.
1 change: 0 additions & 1 deletion src/test/ui/parser/issue-10392.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ fn a() -> A { panic!() }

fn main() {
let A { , } = a(); //~ ERROR expected ident
//~| ERROR pattern does not mention field `foo`
}
9 changes: 1 addition & 8 deletions src/test/ui/parser/issue-10392.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,5 @@ error: expected identifier, found `,`
LL | let A { , } = a();
| ^ expected identifier

error[E0027]: pattern does not mention field `foo`
--> $DIR/issue-10392.rs:6:9
|
LL | let A { , } = a();
| ^^^^^^^ missing field `foo`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0027`.
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-54379.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn main() {
let thing = MyStruct { s1: None };

match thing {
MyStruct { .., Some(_) } => {}, //~ ERROR pattern does not mention field `s1`
MyStruct { .., Some(_) } => {},
//~^ ERROR expected `,`
//~| ERROR expected `}`, found `,`
_ => {}
Expand Down
9 changes: 1 addition & 8 deletions src/test/ui/resolve/issue-54379.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,5 @@ error: expected `,`
LL | MyStruct { .., Some(_) } => {},
| ^^^^

error[E0027]: pattern does not mention field `s1`
--> $DIR/issue-54379.rs:9:9
|
LL | MyStruct { .., Some(_) } => {},
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing field `s1`

error: aborting due to 3 previous errors
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0027`.