Skip to content

Commit

Permalink
Rollup merge of rust-lang#87646 - JohnTitor:fix-parser-ice, r=oli-obk
Browse files Browse the repository at this point in the history
Fix a parser ICE on invalid `fn` body

Fixes rust-lang#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`
  • Loading branch information
JohnTitor authored Aug 3, 2021
2 parents 8bce8ef + d2d8519 commit f9070ca
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/parser/issue-87635.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct Foo {}

impl Foo {
pub fn bar()
//~^ ERROR: expected `;`, found `}`
//~| ERROR: associated function in `impl` without body
}

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/parser/issue-87635.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f9070ca

Please sign in to comment.