about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-12-16 19:32:19 +0000
committerbors <bors@rust-lang.org>2017-12-16 19:32:19 +0000
commit3bee2b44cfd5610ad0346f0179602d91a8dedfd0 (patch)
tree605ec9c821f54db3f9f3bc95da4ed84ae4aaa279 /src/libsyntax/parse/parser.rs
parent4f2ef415ba1e64d843ee58e95009871053d3f7a6 (diff)
parentd40197c47196d4abb8ecb897a64ac11026d95623 (diff)
downloadrust-3bee2b44cfd5610ad0346f0179602d91a8dedfd0.tar.gz
rust-3bee2b44cfd5610ad0346f0179602d91a8dedfd0.zip
Auto merge of #46763 - zackmdavis:and_the_case_of_the_erroneous_field_pattern_ellipsis, r=petrochenkov
in which `..` is suggested for erroneous `...` in struct field patterns

Resolves #46718. Supersedes #46721.

r? @petrochenkov
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();