diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-04 03:31:32 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-23 13:27:44 +0100 |
| commit | 8480b31ba9ca615d6c1e3e6a4a42d5757b447a0c (patch) | |
| tree | 8c2fae36133b7d8ea957b6d53b70cc515720bff6 /src/librustc_parse | |
| parent | e77b9d36ca5b33c7c76ca420b4021dadb8b2a05e (diff) | |
| download | rust-8480b31ba9ca615d6c1e3e6a4a42d5757b447a0c.tar.gz rust-8480b31ba9ca615d6c1e3e6a4a42d5757b447a0c.zip | |
extract recover_struct_comma_after_dotdot
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index ce17b8fa546..28b49d01b7e 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -1788,21 +1788,7 @@ impl<'a> Parser<'a> { self.recover_stmt(); } } - if self.token == token::Comma { - self.struct_span_err( - exp_span.to(self.prev_span), - "cannot use a comma after the base struct", - ) - .span_suggestion_short( - self.token.span, - "remove this comma", - String::new(), - Applicability::MachineApplicable, - ) - .note("the base struct must always be the last field") - .emit(); - self.recover_stmt(); - } + self.recover_struct_comma_after_dotdot(exp_span); break; } @@ -1864,6 +1850,22 @@ impl<'a> Parser<'a> { return Ok(self.mk_expr(span, ExprKind::Struct(pth, fields, base), attrs)); } + fn recover_struct_comma_after_dotdot(&mut self, span: Span) { + if self.token != token::Comma { + return; + } + self.struct_span_err(span.to(self.prev_span), "cannot use a comma after the base struct") + .span_suggestion_short( + self.token.span, + "remove this comma", + String::new(), + Applicability::MachineApplicable, + ) + .note("the base struct must always be the last field") + .emit(); + self.recover_stmt(); + } + /// Parses `ident (COLON expr)?`. fn parse_field(&mut self) -> PResult<'a, Field> { let attrs = self.parse_outer_attributes()?.into(); |
