Skip to content

Commit 8d05997

Browse files
authored
Rollup merge of #66361 - Centril:66357, r=pnkfelix
parser: don't use `unreachable!()` in `fn unexpected`. Fixes #66357 r? @estebank
2 parents 28c0e40 + dcd91d5 commit 8d05997

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/librustc_parse/parser/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,9 @@ impl<'a> Parser<'a> {
443443
crate fn unexpected<T>(&mut self) -> PResult<'a, T> {
444444
match self.expect_one_of(&[], &[]) {
445445
Err(e) => Err(e),
446-
Ok(_) => unreachable!(),
446+
// We can get `Ok(true)` from `recover_closing_delimiter`
447+
// which is called in `expected_one_of_not_found`.
448+
Ok(_) => FatalError.raise(),
447449
}
448450
}
449451

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// The problem in #66357 was that the call trace:
2+
//
3+
// - parse_fn_block_decl
4+
// - expect_or
5+
// - unexpected
6+
// - expect_one_of
7+
// - expected_one_of_not_found
8+
// - recover_closing_delimiter
9+
//
10+
// ended up bubbling up `Ok(true)` to `unexpected` which then used `unreachable!()`.
11+
12+
fn f() { |[](* }
13+
//~^ ERROR expected one of `,` or `:`, found `(`
14+
//~| ERROR expected one of `)`, `-`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: expected one of `,` or `:`, found `(`
2+
--> $DIR/issue-66357-unexpected-unreachable.rs:12:13
3+
|
4+
LL | fn f() { |[](* }
5+
| ^ expected one of `,` or `:`
6+
7+
error: expected one of `)`, `-`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
8+
--> $DIR/issue-66357-unexpected-unreachable.rs:12:14
9+
|
10+
LL | fn f() { |[](* }
11+
| -^ help: `)` may belong here
12+
| |
13+
| unclosed delimiter
14+
15+
error: aborting due to 2 previous errors
16+

0 commit comments

Comments
 (0)