Skip to content

Commit d2d8519

Browse files
committed
Fix a parser ICE on invalid fn body
1 parent f3f8e75 commit d2d8519

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
@@ -1715,13 +1715,11 @@ impl<'a> Parser<'a> {
17151715
// the AST for typechecking.
17161716
err.span_label(ident.span, "while parsing this `fn`");
17171717
err.emit();
1718-
(Vec::new(), None)
17191718
} else {
17201719
return Err(err);
17211720
}
1722-
} else {
1723-
unreachable!()
17241721
}
1722+
(Vec::new(), None)
17251723
};
17261724
attrs.extend(inner_attrs);
17271725
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)