1
Fork 0

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.
This commit is contained in:
Esteban Küber 2018-05-29 16:37:06 -07:00
parent 41affd03eb
commit 8f4a5429c2
3 changed files with 11 additions and 8 deletions

View file

@ -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 `}`");
}