From 1495d304483bb73c408295523ca458f2691e9732 Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Tue, 5 Feb 2019 02:25:06 -0800 Subject: Remove spurious complaint about missing expression for bare semicolons --- src/libsyntax/parse/parser.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 4a932ab7bd1..742a493a2f9 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; -- cgit 1.4.1-3-g733a5