about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorLamb <lambtowolf@protonmail.com>2018-05-29 13:19:58 +0200
committerPietro Albini <pietro@pietroalbini.org>2018-06-22 11:38:38 +0200
commit7969b78222dc66e21c6a21470365f404992729b1 (patch)
treebfbf0820fb4efd2caa58132f38cd01948eb7de51 /src/libsyntax/parse
parent7dae5c0e06f10042fc3b29a55bf6285e539c06db (diff)
downloadrust-7969b78222dc66e21c6a21470365f404992729b1.tar.gz
rust-7969b78222dc66e21c6a21470365f404992729b1.zip
Issue #50974: Suboptimal error in case of duplicate `,` in struct constructor
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 3955ccb4c42..3d386708645 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 {
+                err.span_suggestion(self.span, "try removing a comma", ",".into());
+            }
         }
         err
     }
@@ -2446,8 +2449,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;
+                    }
                 }
             }