about summary refs log tree commit diff
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
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.
-rw-r--r--src/libsyntax/parse/parser.rs6
-rw-r--r--src/test/ui/obsolete-in-place/bad.rs1
-rw-r--r--src/test/ui/obsolete-in-place/bad.stderr17
-rw-r--r--src/test/ui/parser/issue-19096.rs9
-rw-r--r--src/test/ui/parser/issue-19096.stderr13
-rw-r--r--src/test/ui/parser/raw/raw-literal-keywords.rs15
-rw-r--r--src/test/ui/parser/raw/raw-literal-keywords.stderr22
-rw-r--r--src/test/ui/resolve/token-error-correct-3.rs1
-rw-r--r--src/test/ui/resolve/token-error-correct-3.stderr19
9 files changed, 42 insertions, 61 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))
     }
 
diff --git a/src/test/ui/obsolete-in-place/bad.rs b/src/test/ui/obsolete-in-place/bad.rs
index 67676857e8d..3530862f767 100644
--- a/src/test/ui/obsolete-in-place/bad.rs
+++ b/src/test/ui/obsolete-in-place/bad.rs
@@ -3,7 +3,6 @@
 fn foo() {
     let (x, y) = (0, 0);
     x <- y; //~ ERROR expected one of
-    //~^ ERROR mismatched types
 }
 
 fn main() {
diff --git a/src/test/ui/obsolete-in-place/bad.stderr b/src/test/ui/obsolete-in-place/bad.stderr
index 91ea82a657d..373b7ea4218 100644
--- a/src/test/ui/obsolete-in-place/bad.stderr
+++ b/src/test/ui/obsolete-in-place/bad.stderr
@@ -5,23 +5,10 @@ LL |     x <- y;
    |       ^^ expected one of 8 possible tokens here
 
 error: expected expression, found keyword `in`
-  --> $DIR/bad.rs:11:5
+  --> $DIR/bad.rs:10:5
    |
 LL |     in(foo) { bar };
    |     ^^ expected expression
 
-error[E0308]: mismatched types
-  --> $DIR/bad.rs:5:5
-   |
-LL | fn foo() {
-   |          - possibly return type missing here?
-LL |     let (x, y) = (0, 0);
-LL |     x <- y;
-   |     ^ expected (), found integer
-   |
-   = note: expected type `()`
-              found type `{integer}`
-
-error: aborting due to 3 previous errors
+error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/parser/issue-19096.rs b/src/test/ui/parser/issue-19096.rs
index edc69e6f49f..c5bfd10ee5e 100644
--- a/src/test/ui/parser/issue-19096.rs
+++ b/src/test/ui/parser/issue-19096.rs
@@ -1,5 +1,10 @@
-fn main() {
+fn main() { // we don't complain about the return type being `{integer}`
     let t = (42, 42);
     t.0::<isize>; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
-                  //~| ERROR mismatched types
+}
+
+fn foo() -> usize { // we don't complain about the return type being unit
+    let t = (42, 42);
+    t.0::<isize>; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
+    42;
 }
diff --git a/src/test/ui/parser/issue-19096.stderr b/src/test/ui/parser/issue-19096.stderr
index 6aa97add7b0..957b40dbd5e 100644
--- a/src/test/ui/parser/issue-19096.stderr
+++ b/src/test/ui/parser/issue-19096.stderr
@@ -4,18 +4,11 @@ error: expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
 LL |     t.0::<isize>;
    |        ^^ expected one of `.`, `;`, `?`, `}`, or an operator here
 
-error[E0308]: mismatched types
-  --> $DIR/issue-19096.rs:3:5
+error: expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
+  --> $DIR/issue-19096.rs:8:8
    |
-LL | fn main() {
-   |           - expected `()` because of default return type
-LL |     let t = (42, 42);
 LL |     t.0::<isize>;
-   |     ^^^ expected (), found integer
-   |
-   = note: expected type `()`
-              found type `{integer}`
+   |        ^^ expected one of `.`, `;`, `?`, `}`, or an operator here
 
 error: aborting due to 2 previous errors
 
-For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/parser/raw/raw-literal-keywords.rs b/src/test/ui/parser/raw/raw-literal-keywords.rs
index f51e565c2d3..6b055fbb117 100644
--- a/src/test/ui/parser/raw/raw-literal-keywords.rs
+++ b/src/test/ui/parser/raw/raw-literal-keywords.rs
@@ -1,16 +1,25 @@
 fn test_if() {
     r#if true { } //~ ERROR found `true`
-                  //~| ERROR cannot find value `if` in this scope
 }
 
 fn test_struct() {
     r#struct Test; //~ ERROR found `Test`
-                   //~| ERROR cannot find value `struct` in this scope
 }
 
 fn test_union() {
     r#union Test; //~ ERROR found `Test`
-                  //~| ERROR cannot find value `union` in this scope
+}
+
+fn test_if_2() {
+    let _ = r#if; //~ ERROR cannot find value `if` in this scope
+}
+
+fn test_struct_2() {
+    let _ = r#struct; //~ ERROR cannot find value `struct` in this scope
+}
+
+fn test_union_2() {
+    let _ = r#union; //~ ERROR cannot find value `union` in this scope
 }
 
 fn main() {}
diff --git a/src/test/ui/parser/raw/raw-literal-keywords.stderr b/src/test/ui/parser/raw/raw-literal-keywords.stderr
index 8b8b71373b5..f39e29cfaa8 100644
--- a/src/test/ui/parser/raw/raw-literal-keywords.stderr
+++ b/src/test/ui/parser/raw/raw-literal-keywords.stderr
@@ -5,34 +5,34 @@ LL |     r#if true { }
    |          ^^^^ expected one of 8 possible tokens here
 
 error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
-  --> $DIR/raw-literal-keywords.rs:7:14
+  --> $DIR/raw-literal-keywords.rs:6:14
    |
 LL |     r#struct Test;
    |              ^^^^ expected one of 8 possible tokens here
 
 error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
-  --> $DIR/raw-literal-keywords.rs:12:13
+  --> $DIR/raw-literal-keywords.rs:10:13
    |
 LL |     r#union Test;
    |             ^^^^ expected one of 8 possible tokens here
 
 error[E0425]: cannot find value `if` in this scope
-  --> $DIR/raw-literal-keywords.rs:2:5
+  --> $DIR/raw-literal-keywords.rs:14:13
    |
-LL |     r#if true { }
-   |     ^^^^ not found in this scope
+LL |     let _ = r#if;
+   |             ^^^^ not found in this scope
 
 error[E0425]: cannot find value `struct` in this scope
-  --> $DIR/raw-literal-keywords.rs:7:5
+  --> $DIR/raw-literal-keywords.rs:18:13
    |
-LL |     r#struct Test;
-   |     ^^^^^^^^ not found in this scope
+LL |     let _ = r#struct;
+   |             ^^^^^^^^ not found in this scope
 
 error[E0425]: cannot find value `union` in this scope
-  --> $DIR/raw-literal-keywords.rs:12:5
+  --> $DIR/raw-literal-keywords.rs:22:13
    |
-LL |     r#union Test;
-   |     ^^^^^^^ not found in this scope
+LL |     let _ = r#union;
+   |             ^^^^^^^ not found in this scope
 
 error: aborting due to 6 previous errors
 
diff --git a/src/test/ui/resolve/token-error-correct-3.rs b/src/test/ui/resolve/token-error-correct-3.rs
index 212b88ac8b0..5b08234c0ad 100644
--- a/src/test/ui/resolve/token-error-correct-3.rs
+++ b/src/test/ui/resolve/token-error-correct-3.rs
@@ -15,7 +15,6 @@ pub mod raw {
             callback(path.as_ref();
             //~^ ERROR expected one of
             fs::create_dir_all(path.as_ref()).map(|()| true)
-            //~^ ERROR mismatched types
         } else {
             //~^ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
             Ok(false);
diff --git a/src/test/ui/resolve/token-error-correct-3.stderr b/src/test/ui/resolve/token-error-correct-3.stderr
index 607573f2769..57dd7c9f034 100644
--- a/src/test/ui/resolve/token-error-correct-3.stderr
+++ b/src/test/ui/resolve/token-error-correct-3.stderr
@@ -7,11 +7,10 @@ LL |             callback(path.as_ref();
    |                     unclosed delimiter
 
 error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
-  --> $DIR/token-error-correct-3.rs:19:9
+  --> $DIR/token-error-correct-3.rs:18:9
    |
 LL |             fs::create_dir_all(path.as_ref()).map(|()| true)
    |                                                             - expected one of `.`, `;`, `?`, `}`, or an operator here
-LL |
 LL |         } else {
    |         ^ unexpected token
 
@@ -21,18 +20,6 @@ error[E0425]: cannot find function `is_directory` in this scope
 LL |         if !is_directory(path.as_ref()) {
    |             ^^^^^^^^^^^^ not found in this scope
 
-error[E0308]: mismatched types
-  --> $DIR/token-error-correct-3.rs:17:13
-   |
-LL |             fs::create_dir_all(path.as_ref()).map(|()| true)
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
-   |             |
-   |             expected (), found enum `std::result::Result`
-   |
-   = note: expected type `()`
-              found type `std::result::Result<bool, std::io::Error>`
-
-error: aborting due to 4 previous errors
+error: aborting due to 3 previous errors
 
-Some errors have detailed explanations: E0308, E0425.
-For more information about an error, try `rustc --explain E0308`.
+For more information about this error, try `rustc --explain E0425`.