about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-02-05 02:25:06 -0800
committerEsteban Küber <esteban@kuber.com.ar>2019-02-07 01:42:54 -0800
commit1495d304483bb73c408295523ca458f2691e9732 (patch)
tree1bbe6d889ed8403f5bc4319cf6802c4c191601a0 /src/libsyntax/parse
parent99be87aac3b9af941e74b8681643e1963ce75671 (diff)
downloadrust-1495d304483bb73c408295523ca458f2691e9732.tar.gz
rust-1495d304483bb73c408295523ca458f2691e9732.zip
Remove spurious complaint about missing expression for bare semicolons
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/parser.rs17
1 files changed, 16 insertions, 1 deletions
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;