From daa5b81c632f6725f3a696930bc5ed436066cbf9 Mon Sep 17 00:00:00 2001 From: Lamb Date: Tue, 29 May 2018 13:19:58 +0200 Subject: [PATCH] Issue #50974: Suboptimal error in case of duplicate `,` in struct constructor --- src/libsyntax/parse/parser.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 28f93328e9534..b39c050269ed2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -767,6 +767,9 @@ impl<'a> Parser<'a> { err.span_label(self.span, format!("expected identifier, found {}", token_descr)); } else { err.span_label(self.span, "expected identifier"); + if self.token == token::Comma { + err.span_suggestion(self.span, "try removing a comma", ",".into()); + } } err } @@ -2527,8 +2530,11 @@ impl<'a> Parser<'a> { Err(mut e) => { e.span_label(struct_sp, "while parsing this struct"); e.emit(); - self.recover_stmt(); - break; + + if self.token != token::Comma { + self.recover_stmt(); + break; + } } }