Skip to content

Commit a43380f

Browse files
authored
Rollup merge of rust-lang#108244 - lukas-code:semicolon-recovery-span, 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
2 parents 7dd9f29 + 611ab68 commit a43380f

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ impl<'a> Parser<'a> {
14011401
// 2 | foo(bar(;
14021402
// | ^ expected expression
14031403
self.bump();
1404-
Ok(self.mk_expr_err(self.token.span))
1404+
Ok(self.mk_expr_err(self.prev_token.span))
14051405
} else if self.token.uninterpolated_span().rust_2018() {
14061406
// `Span::rust_2018()` is somewhat expensive; don't get it repeatedly.
14071407
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)