Skip to content

Commit

Permalink
use span of semicolon for eager recovery in expression
Browse files Browse the repository at this point in the history
instead of the span of the token after the semicolon
  • Loading branch information
Lukas Markeffsky committed Feb 22, 2023
1 parent 3b4d6e0 commit 611ab68
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 611ab68

Please sign in to comment.