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
This commit is contained in:
Dylan DPC 2020-05-27 03:09:11 +02:00 committed by GitHub
commit cbe7b908b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -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)

View File

@ -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();
}

View File

@ -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