diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index ce17b8fa5464..28b49d01b7eb 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();