diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-05-27 03:09:11 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-27 03:09:11 +0200 |
| commit | cbe7b908b124047aaff5f1bed1056a71ca0a6b3b (patch) | |
| tree | 0f6d0509a62deecc891a04ec777eb839b7e15d3b | |
| parent | e5335592e78354e33d798d20c04bcd677c1df62d (diff) | |
| parent | f384cdcbecf46db38e46177700d29e881dcb53b7 (diff) | |
| download | rust-cbe7b908b124047aaff5f1bed1056a71ca0a6b3b.tar.gz rust-cbe7b908b124047aaff5f1bed1056a71ca0a6b3b.zip | |
Rollup merge of #72348 - chrissimpkins:fix-72253, r=estebank
Fix confusing error message for comma typo in multiline statement Fixes #72253. Expands on the issue with a colon typo check. r? @estebank cc @ehuss
| -rw-r--r-- | src/librustc_parse/parser/diagnostics.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-72253.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-72253.stderr | 10 |
3 files changed, 29 insertions, 0 deletions
diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index f05d0186138..660a63841bc 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -935,6 +935,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 + |
