Skip to content

Commit

Permalink
improve error message for unexpected comma token in multiline block
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chrissimpkins committed May 26, 2020
1 parent 914adf0 commit f384cdc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/librustc_parse/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/issues/issue-72253.rs
Original file line number Diff line number Diff line change
@@ -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();
}
10 changes: 10 additions & 0 deletions src/test/ui/issues/issue-72253.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f384cdc

Please sign in to comment.