about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChris Simpkins <git.simpkins@gmail.com>2020-05-26 16:52:16 -0400
committerChris Simpkins <git.simpkins@gmail.com>2020-05-26 16:52:16 -0400
commitf384cdcbecf46db38e46177700d29e881dcb53b7 (patch)
tree340f3baeb6e674beb1361995d8ae3ad1f6b75d87
parent914adf04af1c1a984707f778da3d04590c03d144 (diff)
downloadrust-f384cdcbecf46db38e46177700d29e881dcb53b7.tar.gz
rust-f384cdcbecf46db38e46177700d29e881dcb53b7.zip
improve error message for unexpected comma token in multiline block
confusing diagnostics, issue #72253

add test for confusing error message, issue-72253


remove is_multiline check, refactor to self.expect(&token:Semi)


update issue-72253 tests


return Ok

-rw-r--r--src/librustc_parse/parser/diagnostics.rs13
-rw-r--r--src/test/ui/issues/issue-72253.rs6
-rw-r--r--src/test/ui/issues/issue-72253.stderr10
3 files changed, 29 insertions, 0 deletions
diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs
index 93c7faf22a7..079059ec751 100644
--- a/src/librustc_parse/parser/diagnostics.rs
+++ b/src/librustc_parse/parser/diagnostics.rs
@@ -934,6 +934,19 @@ impl<'a> Parser<'a> {
             return self.expect(&token::Semi).map(drop);
         } else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
             // The current token is in the same line as the prior token, not recoverable.
+        } else if [token::Comma, token::Colon].contains(&self.token.kind)
+            && &self.prev_token.kind == &token::CloseDelim(token::Paren)
+        {
+            // Likely typo: The current token is on a new line and is expected to be
+            // `.`, `;`, `?`, or an operator after a close delimiter token.
+            //
+            // let a = std::process::Command::new("echo")
+            //         .arg("1")
+            //         ,arg("2")
+            //         ^
+            // https://github.com/rust-lang/rust/issues/72253
+            self.expect(&token::Semi)?;
+            return Ok(());
         } else if self.look_ahead(1, |t| {
             t == &token::CloseDelim(token::Brace) || t.can_begin_expr() && t.kind != token::Colon
         }) && [token::Comma, token::Colon].contains(&self.token.kind)
diff --git a/src/test/ui/issues/issue-72253.rs b/src/test/ui/issues/issue-72253.rs
new file mode 100644
index 00000000000..6f9af73b039
--- /dev/null
+++ b/src/test/ui/issues/issue-72253.rs
@@ -0,0 +1,6 @@
+fn main() {
+    let a = std::process::Command::new("echo")
+        .arg("1")
+        ,arg("2") //~ ERROR expected one of `.`, `;`, `?`, or an operator, found `,`
+        .output();
+}
diff --git a/src/test/ui/issues/issue-72253.stderr b/src/test/ui/issues/issue-72253.stderr
new file mode 100644
index 00000000000..3819fd92a9e
--- /dev/null
+++ b/src/test/ui/issues/issue-72253.stderr
@@ -0,0 +1,10 @@
+error: expected one of `.`, `;`, `?`, or an operator, found `,`
+  --> $DIR/issue-72253.rs:4:9
+   |
+LL |         .arg("1")
+   |                  - expected one of `.`, `;`, `?`, or an operator
+LL |         ,arg("2")
+   |         ^ unexpected token
+
+error: aborting due to previous error
+