about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorZack M. Davis <code@zackmdavis.net>2017-12-16 00:58:19 -0800
committerZack M. Davis <code@zackmdavis.net>2017-12-16 00:58:19 -0800
commitd40197c47196d4abb8ecb897a64ac11026d95623 (patch)
tree8eea369af36d487dd74a557c7ec410771f025769 /src/libsyntax/parse/parser.rs
parentb3392f8ae4074de4de15befee871ad8b1523a2ed (diff)
downloadrust-d40197c47196d4abb8ecb897a64ac11026d95623.tar.gz
rust-d40197c47196d4abb8ecb897a64ac11026d95623.zip
in which `..` is suggested for erroneous `...` in struct field patterns
Resolves #46718.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index ec77d85f030..2158c4a4fe4 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1212,6 +1212,9 @@ impl<'a> Parser<'a> {
     pub fn span_err(&self, sp: Span, m: &str) {
         self.sess.span_diagnostic.span_err(sp, m)
     }
+    pub fn struct_span_err(&self, sp: Span, m: &str) -> DiagnosticBuilder<'a> {
+        self.sess.span_diagnostic.struct_span_err(sp, m)
+    }
     pub fn span_err_help(&self, sp: Span, m: &str, h: &str) {
         let mut err = self.sess.span_diagnostic.mut_span_err(sp, m);
         err.help(h);
@@ -3445,7 +3448,16 @@ impl<'a> Parser<'a> {
             let lo = self.span;
             let hi;
 
-            if self.check(&token::DotDot) {
+            if self.check(&token::DotDot) || self.token == token::DotDotDot {
+                if self.token == token::DotDotDot { // Issue #46718
+                    let mut err = self.struct_span_err(self.span,
+                                                       "expected field pattern, found `...`");
+                    err.span_suggestion(self.span,
+                                        "to omit remaining fields, use one fewer `.`",
+                                        "..".to_owned());
+                    err.emit();
+                }
+
                 self.bump();
                 if self.token != token::CloseDelim(token::Brace) {
                     let token_str = self.this_token_to_string();