mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
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:
commit
cbe7b908b1
@ -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)
|
||||
|
6
src/test/ui/issues/issue-72253.rs
Normal file
6
src/test/ui/issues/issue-72253.rs
Normal 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();
|
||||
}
|
10
src/test/ui/issues/issue-72253.stderr
Normal file
10
src/test/ui/issues/issue-72253.stderr
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user