Skip to content

Commit

Permalink
Rollup merge of rust-lang#108244 - lukas-code:semicolon-recovery-span…
Browse files Browse the repository at this point in the history
…, r=compiler-errors

Use span of semicolon for eager recovery in expression

Instead of the span of the token after the semicolon. This will hopefully cause fewer errors from overlapping spans.

fixes rust-lang#108242
based on rust-lang#108239
  • Loading branch information
matthiaskrgr committed Mar 1, 2023
2 parents 19ff1f2 + 611ab68 commit 5b64847
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 @@ -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) {
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 5b64847

Please sign in to comment.