about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-08-03 19:07:44 +0900
committerGitHub <noreply@github.com>2021-08-03 19:07:44 +0900
commitf69daa261742f447f269d1ee9f814dfd5cb4eb1b (patch)
tree50c0a0d230dbf2519d669e808e6f3aec02d1d90d
parent345862d2245c2fe132c793ab528709045b38beaa (diff)
parentd2d851949bab4c96b54d11126a0efd1826557d3f (diff)
downloadrust-f69daa261742f447f269d1ee9f814dfd5cb4eb1b.tar.gz
rust-f69daa261742f447f269d1ee9f814dfd5cb4eb1b.zip
Rollup merge of #87646 - JohnTitor:fix-parser-ice, r=oli-obk
Fix a parser ICE on invalid `fn` body

Fixes #87635
A better fix would add a check for `fn` body on `expected_one_of_not_found` but I haven't come up with a graceful way. Any idea?
r? ```@oli-obk``` ```@estebank```
-rw-r--r--compiler/rustc_parse/src/parser/item.rs4
-rw-r--r--src/test/ui/parser/issue-87635.rs9
-rw-r--r--src/test/ui/parser/issue-87635.stderr19
3 files changed, 29 insertions, 3 deletions
diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs
index f77f9bc454b..9fcf2c4d5ec 100644
--- a/compiler/rustc_parse/src/parser/item.rs
+++ b/compiler/rustc_parse/src/parser/item.rs
@@ -1714,13 +1714,11 @@ impl<'a> Parser<'a> {
                     // the AST for typechecking.
                     err.span_label(ident.span, "while parsing this `fn`");
                     err.emit();
-                    (Vec::new(), None)
                 } else {
                     return Err(err);
                 }
-            } else {
-                unreachable!()
             }
+            (Vec::new(), None)
         };
         attrs.extend(inner_attrs);
         Ok(body)
diff --git a/src/test/ui/parser/issue-87635.rs b/src/test/ui/parser/issue-87635.rs
new file mode 100644
index 00000000000..da74c1877b1
--- /dev/null
+++ b/src/test/ui/parser/issue-87635.rs
@@ -0,0 +1,9 @@
+struct Foo {}
+
+impl Foo {
+    pub fn bar()
+    //~^ ERROR: expected `;`, found `}`
+    //~| ERROR: associated function in `impl` without body
+}
+
+fn main() {}
diff --git a/src/test/ui/parser/issue-87635.stderr b/src/test/ui/parser/issue-87635.stderr
new file mode 100644
index 00000000000..920a9f937dd
--- /dev/null
+++ b/src/test/ui/parser/issue-87635.stderr
@@ -0,0 +1,19 @@
+error: expected `;`, found `}`
+  --> $DIR/issue-87635.rs:4:17
+   |
+LL |     pub fn bar()
+   |                 ^ help: add `;` here
+...
+LL | }
+   | - unexpected token
+
+error: associated function in `impl` without body
+  --> $DIR/issue-87635.rs:4:5
+   |
+LL |     pub fn bar()
+   |     ^^^^^^^^^^^-
+   |                |
+   |                help: provide a definition for the function: `{ <body> }`
+
+error: aborting due to 2 previous errors
+