diff options
| author | Yuki Okushi <yuki.okushi@huawei.com> | 2021-07-31 06:09:54 +0900 |
|---|---|---|
| committer | Yuki Okushi <yuki.okushi@huawei.com> | 2021-07-31 06:09:54 +0900 |
| commit | d2d851949bab4c96b54d11126a0efd1826557d3f (patch) | |
| tree | 3e8393a6f4eba91ef540c48e6ec7a0c1a687e149 | |
| parent | f3f8e758f2b2abd84b76bcb4ec0b6ae263e1e7b9 (diff) | |
| download | rust-d2d851949bab4c96b54d11126a0efd1826557d3f.tar.gz rust-d2d851949bab4c96b54d11126a0efd1826557d3f.zip | |
Fix a parser ICE on invalid `fn` body
| -rw-r--r-- | compiler/rustc_parse/src/parser/item.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-87635.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/parser/issue-87635.stderr | 19 |
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 2ce63d011f4..1e4bc49cb39 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1715,13 +1715,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 + |
