Skip to content

Commit 611ab68

Browse files
author
Lukas Markeffsky
committed
use span of semicolon for eager recovery in expression
instead of the span of the token after the semicolon
1 parent 3b4d6e0 commit 611ab68

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

Diff for: compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ impl<'a> Parser<'a> {
13891389
// 2 | foo(bar(;
13901390
// | ^ expected expression
13911391
self.bump();
1392-
Ok(self.mk_expr_err(self.token.span))
1392+
Ok(self.mk_expr_err(self.prev_token.span))
13931393
} else if self.token.uninterpolated_span().rust_2018() {
13941394
// `Span::rust_2018()` is somewhat expensive; don't get it repeatedly.
13951395
if self.check_keyword(kw::Async) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo() {}
2+
fn main() {
3+
foo(; //~ ERROR this function takes 0 arguments but 2 arguments were supplied
4+
foo(; //~ ERROR this function takes 0 arguments but 1 argument was supplied
5+
//~^ ERROR expected one of
6+
} //~ ERROR mismatched closing delimiter
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `foo`
2+
--> $DIR/issue-108242-semicolon-recovery.rs:4:5
3+
|
4+
LL | foo(;
5+
| -
6+
| |
7+
| expected one of `)`, `,`, `.`, `?`, or an operator
8+
| help: missing `,`
9+
LL | foo(;
10+
| ^^^ unexpected token
11+
12+
error: mismatched closing delimiter: `}`
13+
--> $DIR/issue-108242-semicolon-recovery.rs:4:8
14+
|
15+
LL | fn main() {
16+
| - closing delimiter possibly meant for this
17+
LL | foo(;
18+
LL | foo(;
19+
| ^ unclosed delimiter
20+
LL |
21+
LL | }
22+
| ^ mismatched closing delimiter
23+
24+
error[E0061]: this function takes 0 arguments but 1 argument was supplied
25+
--> $DIR/issue-108242-semicolon-recovery.rs:4:5
26+
|
27+
LL | foo(;
28+
| ^^^ -
29+
| |
30+
| unexpected argument
31+
| help: remove the extra argument
32+
|
33+
note: function defined here
34+
--> $DIR/issue-108242-semicolon-recovery.rs:1:4
35+
|
36+
LL | fn foo() {}
37+
| ^^^
38+
39+
error[E0061]: this function takes 0 arguments but 2 arguments were supplied
40+
--> $DIR/issue-108242-semicolon-recovery.rs:3:5
41+
|
42+
LL | foo(;
43+
| ^^^ - unexpected argument
44+
LL | / foo(;
45+
LL | |
46+
LL | | }
47+
| |_- unexpected argument of type `()`
48+
|
49+
note: function defined here
50+
--> $DIR/issue-108242-semicolon-recovery.rs:1:4
51+
|
52+
LL | fn foo() {}
53+
| ^^^
54+
help: remove the extra arguments
55+
|
56+
LL - foo(;
57+
LL + foo(
58+
|
59+
60+
error: aborting due to 4 previous errors
61+
62+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)