diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 24d4c17f5d8ab..0be7915088004 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1401,7 +1401,7 @@ impl<'a> Parser<'a> { // 2 | foo(bar(; // | ^ expected expression self.bump(); - Ok(self.mk_expr_err(self.token.span)) + Ok(self.mk_expr_err(self.prev_token.span)) } else if self.token.uninterpolated_span().rust_2018() { // `Span::rust_2018()` is somewhat expensive; don't get it repeatedly. if self.check_keyword(kw::Async) { diff --git a/tests/ui/argument-suggestions/issue-108242-semicolon-recovery.rs b/tests/ui/argument-suggestions/issue-108242-semicolon-recovery.rs new file mode 100644 index 0000000000000..7cab377ea251a --- /dev/null +++ b/tests/ui/argument-suggestions/issue-108242-semicolon-recovery.rs @@ -0,0 +1,6 @@ +fn foo() {} +fn main() { + foo(; //~ ERROR this function takes 0 arguments but 2 arguments were supplied + foo(; //~ ERROR this function takes 0 arguments but 1 argument was supplied + //~^ ERROR expected one of +} //~ ERROR mismatched closing delimiter diff --git a/tests/ui/argument-suggestions/issue-108242-semicolon-recovery.stderr b/tests/ui/argument-suggestions/issue-108242-semicolon-recovery.stderr new file mode 100644 index 0000000000000..2ed8fd3ea8bbc --- /dev/null +++ b/tests/ui/argument-suggestions/issue-108242-semicolon-recovery.stderr @@ -0,0 +1,62 @@ +error: expected one of `)`, `,`, `.`, `?`, or an operator, found `foo` + --> $DIR/issue-108242-semicolon-recovery.rs:4:5 + | +LL | foo(; + | - + | | + | expected one of `)`, `,`, `.`, `?`, or an operator + | help: missing `,` +LL | foo(; + | ^^^ unexpected token + +error: mismatched closing delimiter: `}` + --> $DIR/issue-108242-semicolon-recovery.rs:4:8 + | +LL | fn main() { + | - closing delimiter possibly meant for this +LL | foo(; +LL | foo(; + | ^ unclosed delimiter +LL | +LL | } + | ^ mismatched closing delimiter + +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/issue-108242-semicolon-recovery.rs:4:5 + | +LL | foo(; + | ^^^ - + | | + | unexpected argument + | help: remove the extra argument + | +note: function defined here + --> $DIR/issue-108242-semicolon-recovery.rs:1:4 + | +LL | fn foo() {} + | ^^^ + +error[E0061]: this function takes 0 arguments but 2 arguments were supplied + --> $DIR/issue-108242-semicolon-recovery.rs:3:5 + | +LL | foo(; + | ^^^ - unexpected argument +LL | / foo(; +LL | | +LL | | } + | |_- unexpected argument of type `()` + | +note: function defined here + --> $DIR/issue-108242-semicolon-recovery.rs:1:4 + | +LL | fn foo() {} + | ^^^ +help: remove the extra arguments + | +LL - foo(; +LL + foo( + | + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0061`.