diff options
| author | Chris Simpkins <git.simpkins@gmail.com> | 2020-05-26 16:52:16 -0400 |
|---|---|---|
| committer | Chris Simpkins <git.simpkins@gmail.com> | 2020-05-26 16:52:16 -0400 |
| commit | f384cdcbecf46db38e46177700d29e881dcb53b7 (patch) | |
| tree | 340f3baeb6e674beb1361995d8ae3ad1f6b75d87 /src/librustc_parse/parser | |
| parent | 914adf04af1c1a984707f778da3d04590c03d144 (diff) | |
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
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/diagnostics.rs | 13 |
1 files changed, 13 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) |
