Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Accept .. in incorrect position to avoid further errors
We currently give a specific message when encountering a `..` anywhere
other than the end of a pattern. Modify the parser to accept it (while
still emitting the error) so that we don't also trigger "missing fields
in pattern" errors afterwards.
  • Loading branch information
estebank committed Jun 5, 2018
commit 8f4a5429c2cf7ce1f0a63f821484744024b364f1
10 changes: 10 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3749,6 +3749,16 @@ impl<'a> Parser<'a> {
err.span_label(self.span,
"`..` must be in the last position, \
and cannot have a trailing comma");
if self.look_ahead(1, |t| {
t == &token::CloseDelim(token::Brace) || t.is_ident()
}) {
// If the struct looks otherwise well formed, recover and continue.
// This way we avoid "pattern missing fields" errors afterwards.
err.emit();
self.bump();
etc = true;
break;
}
} else {
err.span_label(self.span, "expected `}`");
}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/issue-49257.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ struct Point { x: u8, y: u8 }
fn main() {
let p = Point { x: 0, y: 0 };
let Point { .., y } = p; //~ ERROR expected `}`, found `,`
//~| ERROR pattern does not mention fields `x`, `y`
}
8 changes: 1 addition & 7 deletions src/test/ui/issue-49257.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ error: expected `}`, found `,`
LL | let Point { .., y } = p; //~ ERROR expected `}`, found `,`
| ^ `..` must be in the last position, and cannot have a trailing comma

error[E0027]: pattern does not mention fields `x`, `y`
--> $DIR/issue-49257.rs:20:9
|
LL | let Point { .., y } = p; //~ ERROR expected `}`, found `,`
| ^^^^^^^^^^^^^^^ missing fields `x`, `y`

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

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