diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4a932ab7bd19..742a493a2f92 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -731,7 +731,7 @@ impl<'a> Parser<'a> { Applicability::MaybeIncorrect, ); err.emit(); - // self.expected_tokens.clear(); // reduce errors + self.expected_tokens.clear(); // reduce errors Ok(true) } _ => Err(err), @@ -2814,6 +2814,21 @@ impl<'a> Parser<'a> { hi = pth.span; ex = ExprKind::Path(None, pth); } 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() { Ok(expr) => { hi = expr.span; diff --git a/src/test/ui/resolve/token-error-correct.rs b/src/test/ui/resolve/token-error-correct.rs index b97e22f7d910..c03ea61beb8a 100644 --- a/src/test/ui/resolve/token-error-correct.rs +++ b/src/test/ui/resolve/token-error-correct.rs @@ -2,6 +2,8 @@ fn main() { foo(bar(; - //~^ ERROR: expected expression, found `;` + //~^ ERROR cannot find function `bar` in this scope } //~^ ERROR: incorrect close delimiter: `}` + +fn foo(_: usize) {} \ No newline at end of file diff --git a/src/test/ui/resolve/token-error-correct.stderr b/src/test/ui/resolve/token-error-correct.stderr index 48a247a5898e..b0827ea7367c 100644 --- a/src/test/ui/resolve/token-error-correct.stderr +++ b/src/test/ui/resolve/token-error-correct.stderr @@ -1,9 +1,3 @@ -error: expected expression, found `;` - --> $DIR/token-error-correct.rs:4:13 - | -LL | foo(bar(; - | ^ expected expression - error: incorrect close delimiter: `}` --> $DIR/token-error-correct.rs:6:1 | @@ -11,9 +5,16 @@ LL | fn main() { | - close delimiter possibly meant for this LL | foo(bar(; | - un-closed delimiter -LL | //~^ ERROR: expected expression, found `;` +LL | //~^ ERROR cannot find function `bar` in this scope LL | } | ^ 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 +For more information about this error, try `rustc --explain E0425`.