about summary refs log tree commit diff
path: root/src/libsyntax/parse/parser.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-07-14 22:51:05 +0000
committerbors <bors@rust-lang.org>2019-07-14 22:51:05 +0000
commitd82fd9ecd3e65a313b0e0bdd24de127d4b566156 (patch)
treef36acbac9268c4d4ac54c729f858ad9e5f446c3e /src/libsyntax/parse/parser.rs
parent83e4eed16ef7adb54a802e3b684427e0e912c2b7 (diff)
parent8259a2dd425a94dbce00999027794f65806de831 (diff)
downloadrust-d82fd9ecd3e65a313b0e0bdd24de127d4b566156.tar.gz
rust-d82fd9ecd3e65a313b0e0bdd24de127d4b566156.zip
Auto merge of #62643 - estebank:parse-recovery-type-errs, r=petrochenkov
Do not emit type errors after parse error in last statement of block

When recovering from a parse error inside a block, do not emit type
errors generating on that block's recovered return expression.

Fix #57383.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
-rw-r--r--src/libsyntax/parse/parser.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 2666cd519f9..2d0902f042d 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4675,6 +4675,9 @@ impl<'a> Parser<'a> {
                     {
                         e.emit();
                         self.recover_stmt();
+                        // Don't complain about type errors in body tail after parse error (#57383).
+                        let sp = expr.span.to(self.prev_span);
+                        stmt.node = StmtKind::Expr(DummyResult::raw_expr(sp, true));
                     }
                 }
             }
@@ -4692,8 +4695,7 @@ impl<'a> Parser<'a> {
         if self.eat(&token::Semi) {
             stmt = stmt.add_trailing_semicolon();
         }
-
-        stmt.span = stmt.span.with_hi(self.prev_span.hi());
+        stmt.span = stmt.span.to(self.prev_span);
         Ok(Some(stmt))
     }