about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-05-29 16:37:06 -0700
committerEsteban Küber <esteban@kuber.com.ar>2018-06-05 08:48:54 -0700
commit8f4a5429c2cf7ce1f0a63f821484744024b364f1 (patch)
treeb4dc63aebe37b459597be25fad53c4fd2f08e5e4
parent41affd03eb169830773cd1b11efda562ab81fad0 (diff)
downloadrust-8f4a5429c2cf7ce1f0a63f821484744024b364f1.tar.gz
rust-8f4a5429c2cf7ce1f0a63f821484744024b364f1.zip
Accept `..` in incorrect position to avoid further errors
We currently give a specific message when encountering a `..` anywhere
other than the end of a pattern. Modify the parser to accept it (while
still emitting the error) so that we don't also trigger "missing fields
in pattern" errors afterwards.
-rw-r--r--src/libsyntax/parse/parser.rs10
-rw-r--r--src/test/ui/issue-49257.rs1
-rw-r--r--src/test/ui/issue-49257.stderr8
3 files changed, 11 insertions, 8 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 28f93328e95..5b5ecc4147b 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -3749,6 +3749,16 @@ impl<'a> Parser<'a> {
                         err.span_label(self.span,
                                        "`..` must be in the last position, \
                                         and cannot have a trailing comma");
+                        if self.look_ahead(1, |t| {
+                            t == &token::CloseDelim(token::Brace) || t.is_ident()
+                        }) {
+                            // If the struct looks otherwise well formed, recover and continue.
+                            // This way we avoid "pattern missing fields" errors afterwards.
+                            err.emit();
+                            self.bump();
+                            etc = true;
+                            break;
+                        }
                     } else {
                         err.span_label(self.span, "expected `}`");
                     }
diff --git a/src/test/ui/issue-49257.rs b/src/test/ui/issue-49257.rs
index a3198492237..edb4037d109 100644
--- a/src/test/ui/issue-49257.rs
+++ b/src/test/ui/issue-49257.rs
@@ -18,5 +18,4 @@ struct Point { x: u8, y: u8 }
 fn main() {
     let p = Point { x: 0, y: 0 };
     let Point { .., y } = p; //~ ERROR expected `}`, found `,`
-    //~| ERROR pattern does not mention fields `x`, `y`
 }
diff --git a/src/test/ui/issue-49257.stderr b/src/test/ui/issue-49257.stderr
index fec990764bb..6ca8d80fa2e 100644
--- a/src/test/ui/issue-49257.stderr
+++ b/src/test/ui/issue-49257.stderr
@@ -4,12 +4,6 @@ error: expected `}`, found `,`
 LL |     let Point { .., y } = p; //~ ERROR expected `}`, found `,`
    |                   ^ `..` must be in the last position, and cannot have a trailing comma
 
-error[E0027]: pattern does not mention fields `x`, `y`
-  --> $DIR/issue-49257.rs:20:9
-   |
-LL |     let Point { .., y } = p; //~ ERROR expected `}`, found `,`
-   |         ^^^^^^^^^^^^^^^ missing fields `x`, `y`
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
 For more information about this error, try `rustc --explain E0027`.