Remove spurious complaint about missing expression for bare semicolons
This commit is contained in:
parent
99be87aac3
commit
1495d30448
3 changed files with 27 additions and 9 deletions
|
@ -731,7 +731,7 @@ impl<'a> Parser<'a> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
err.emit();
|
err.emit();
|
||||||
// self.expected_tokens.clear(); // reduce errors
|
self.expected_tokens.clear(); // reduce errors
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
_ => Err(err),
|
_ => Err(err),
|
||||||
|
@ -2814,6 +2814,21 @@ impl<'a> Parser<'a> {
|
||||||
hi = pth.span;
|
hi = pth.span;
|
||||||
ex = ExprKind::Path(None, pth);
|
ex = ExprKind::Path(None, pth);
|
||||||
} else {
|
} else {
|
||||||
|
if !self.unclosed_delims.is_empty() && self.check(&token::Semi) {
|
||||||
|
// Don't complain about bare semicolons after unclosed braces
|
||||||
|
// recovery in order to keep the error count down. Fixing the
|
||||||
|
// delimiters will possibly also fix the bare semicolon found in
|
||||||
|
// expression context. For example, silence the following error:
|
||||||
|
// ```
|
||||||
|
// error: expected expression, found `;`
|
||||||
|
// --> file.rs:2:13
|
||||||
|
// |
|
||||||
|
// 2 | foo(bar(;
|
||||||
|
// | ^ expected expression
|
||||||
|
// ```
|
||||||
|
self.bump();
|
||||||
|
return Ok(self.mk_expr(self.span, ExprKind::Err, ThinVec::new()));
|
||||||
|
}
|
||||||
match self.parse_literal_maybe_minus() {
|
match self.parse_literal_maybe_minus() {
|
||||||
Ok(expr) => {
|
Ok(expr) => {
|
||||||
hi = expr.span;
|
hi = expr.span;
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
foo(bar(;
|
foo(bar(;
|
||||||
//~^ ERROR: expected expression, found `;`
|
//~^ ERROR cannot find function `bar` in this scope
|
||||||
}
|
}
|
||||||
//~^ ERROR: incorrect close delimiter: `}`
|
//~^ ERROR: incorrect close delimiter: `}`
|
||||||
|
|
||||||
|
fn foo(_: usize) {}
|
|
@ -1,9 +1,3 @@
|
||||||
error: expected expression, found `;`
|
|
||||||
--> $DIR/token-error-correct.rs:4:13
|
|
||||||
|
|
|
||||||
LL | foo(bar(;
|
|
||||||
| ^ expected expression
|
|
||||||
|
|
||||||
error: incorrect close delimiter: `}`
|
error: incorrect close delimiter: `}`
|
||||||
--> $DIR/token-error-correct.rs:6:1
|
--> $DIR/token-error-correct.rs:6:1
|
||||||
|
|
|
|
||||||
|
@ -11,9 +5,16 @@ LL | fn main() {
|
||||||
| - close delimiter possibly meant for this
|
| - close delimiter possibly meant for this
|
||||||
LL | foo(bar(;
|
LL | foo(bar(;
|
||||||
| - un-closed delimiter
|
| - un-closed delimiter
|
||||||
LL | //~^ ERROR: expected expression, found `;`
|
LL | //~^ ERROR cannot find function `bar` in this scope
|
||||||
LL | }
|
LL | }
|
||||||
| ^ incorrect close delimiter
|
| ^ incorrect close delimiter
|
||||||
|
|
||||||
|
error[E0425]: cannot find function `bar` in this scope
|
||||||
|
--> $DIR/token-error-correct.rs:4:9
|
||||||
|
|
|
||||||
|
LL | foo(bar(;
|
||||||
|
| ^^^ not found in this scope
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0425`.
|
||||||
|
|
Loading…
Add table
Reference in a new issue