Skip to content

Commit 1495d30

Browse files
committed
Remove spurious complaint about missing expression for bare semicolons
1 parent 99be87a commit 1495d30

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ impl<'a> Parser<'a> {
731731
Applicability::MaybeIncorrect,
732732
);
733733
err.emit();
734-
// self.expected_tokens.clear(); // reduce errors
734+
self.expected_tokens.clear(); // reduce errors
735735
Ok(true)
736736
}
737737
_ => Err(err),
@@ -2814,6 +2814,21 @@ impl<'a> Parser<'a> {
28142814
hi = pth.span;
28152815
ex = ExprKind::Path(None, pth);
28162816
} else {
2817+
if !self.unclosed_delims.is_empty() && self.check(&token::Semi) {
2818+
// Don't complain about bare semicolons after unclosed braces
2819+
// recovery in order to keep the error count down. Fixing the
2820+
// delimiters will possibly also fix the bare semicolon found in
2821+
// expression context. For example, silence the following error:
2822+
// ```
2823+
// error: expected expression, found `;`
2824+
// --> file.rs:2:13
2825+
// |
2826+
// 2 | foo(bar(;
2827+
// | ^ expected expression
2828+
// ```
2829+
self.bump();
2830+
return Ok(self.mk_expr(self.span, ExprKind::Err, ThinVec::new()));
2831+
}
28172832
match self.parse_literal_maybe_minus() {
28182833
Ok(expr) => {
28192834
hi = expr.span;

src/test/ui/resolve/token-error-correct.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
fn main() {
44
foo(bar(;
5-
//~^ ERROR: expected expression, found `;`
5+
//~^ ERROR cannot find function `bar` in this scope
66
}
77
//~^ ERROR: incorrect close delimiter: `}`
8+
9+
fn foo(_: usize) {}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
error: expected expression, found `;`
2-
--> $DIR/token-error-correct.rs:4:13
3-
|
4-
LL | foo(bar(;
5-
| ^ expected expression
6-
71
error: incorrect close delimiter: `}`
82
--> $DIR/token-error-correct.rs:6:1
93
|
104
LL | fn main() {
115
| - close delimiter possibly meant for this
126
LL | foo(bar(;
137
| - un-closed delimiter
14-
LL | //~^ ERROR: expected expression, found `;`
8+
LL | //~^ ERROR cannot find function `bar` in this scope
159
LL | }
1610
| ^ incorrect close delimiter
1711

12+
error[E0425]: cannot find function `bar` in this scope
13+
--> $DIR/token-error-correct.rs:4:9
14+
|
15+
LL | foo(bar(;
16+
| ^^^ not found in this scope
17+
1818
error: aborting due to 2 previous errors
1919

20+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)