Skip to content

Commit f9070ca

Browse files
authored
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`
2 parents 8bce8ef + d2d8519 commit f9070ca

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

compiler/rustc_parse/src/parser/item.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1714,13 +1714,11 @@ impl<'a> Parser<'a> {
17141714
// the AST for typechecking.
17151715
err.span_label(ident.span, "while parsing this `fn`");
17161716
err.emit();
1717-
(Vec::new(), None)
17181717
} else {
17191718
return Err(err);
17201719
}
1721-
} else {
1722-
unreachable!()
17231720
}
1721+
(Vec::new(), None)
17241722
};
17251723
attrs.extend(inner_attrs);
17261724
Ok(body)

src/test/ui/parser/issue-87635.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct Foo {}
2+
3+
impl Foo {
4+
pub fn bar()
5+
//~^ ERROR: expected `;`, found `}`
6+
//~| ERROR: associated function in `impl` without body
7+
}
8+
9+
fn main() {}

src/test/ui/parser/issue-87635.stderr

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: expected `;`, found `}`
2+
--> $DIR/issue-87635.rs:4:17
3+
|
4+
LL | pub fn bar()
5+
| ^ help: add `;` here
6+
...
7+
LL | }
8+
| - unexpected token
9+
10+
error: associated function in `impl` without body
11+
--> $DIR/issue-87635.rs:4:5
12+
|
13+
LL | pub fn bar()
14+
| ^^^^^^^^^^^-
15+
| |
16+
| help: provide a definition for the function: `{ <body> }`
17+
18+
error: aborting due to 2 previous errors
19+

0 commit comments

Comments
 (0)