about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-06-22 11:10:20 +0000
committerbors <bors@rust-lang.org>2018-06-22 11:10:20 +0000
commit01dbfdaf4f45b68b49332b8785262a3a780d0a19 (patch)
treed837ad0585b2ced405e20bc7f08c60162b8e0c4a /src/libsyntax/parse/parser.rs
parente70ff68aafbb923946856fea201e0251869f0dd5 (diff)
parenta99767f64f400f694aec02655af4b5cb5913609e (diff)
downloadrust-01dbfdaf4f45b68b49332b8785262a3a780d0a19.tar.gz
rust-01dbfdaf4f45b68b49332b8785262a3a780d0a19.zip
Auto merge of #51184 - lambtowolf:master, r=nikomatsakis
Issue #50974 : Suboptimal error in case of duplicate `,` in struct constructor

Fixes #50974
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 3955ccb4c42..dfd896fbda4 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -776,6 +776,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 && self.look_ahead(1, |t| t.is_ident()) {
+                err.span_suggestion(self.span, "remove this comma", "".into());
+            }
         }
         err
     }
@@ -2446,8 +2449,14 @@ impl<'a> Parser<'a> {
                 Err(mut e) => {
                     e.span_label(struct_sp, "while parsing this struct");
                     e.emit();
-                    self.recover_stmt();
-                    break;
+
+                    // If the next token is a comma, then try to parse
+                    // what comes next as additional fields, rather than
+                    // bailing out until next `}`.
+                    if self.token != token::Comma {
+                        self.recover_stmt();
+                        break;
+                    }
                 }
             }