Skip to content

Commit cbe7b90

Browse files
authored
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
2 parents e533559 + f384cdc commit cbe7b90

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/librustc_parse/parser/diagnostics.rs

+13
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,19 @@ impl<'a> Parser<'a> {
935935
return self.expect(&token::Semi).map(drop);
936936
} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
937937
// The current token is in the same line as the prior token, not recoverable.
938+
} else if [token::Comma, token::Colon].contains(&self.token.kind)
939+
&& &self.prev_token.kind == &token::CloseDelim(token::Paren)
940+
{
941+
// Likely typo: The current token is on a new line and is expected to be
942+
// `.`, `;`, `?`, or an operator after a close delimiter token.
943+
//
944+
// let a = std::process::Command::new("echo")
945+
// .arg("1")
946+
// ,arg("2")
947+
// ^
948+
// https://github.com/rust-lang/rust/issues/72253
949+
self.expect(&token::Semi)?;
950+
return Ok(());
938951
} else if self.look_ahead(1, |t| {
939952
t == &token::CloseDelim(token::Brace) || t.can_begin_expr() && t.kind != token::Colon
940953
}) && [token::Comma, token::Colon].contains(&self.token.kind)

src/test/ui/issues/issue-72253.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let a = std::process::Command::new("echo")
3+
.arg("1")
4+
,arg("2") //~ ERROR expected one of `.`, `;`, `?`, or an operator, found `,`
5+
.output();
6+
}

src/test/ui/issues/issue-72253.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected one of `.`, `;`, `?`, or an operator, found `,`
2+
--> $DIR/issue-72253.rs:4:9
3+
|
4+
LL | .arg("1")
5+
| - expected one of `.`, `;`, `?`, or an operator
6+
LL | ,arg("2")
7+
| ^ unexpected token
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)