Rollup merge of #66361 - Centril:66357, r=pnkfelix
parser: don't use `unreachable!()` in `fn unexpected`. Fixes #66357 r? @estebank
This commit is contained in:
commit
8d059974f7
@ -443,7 +443,9 @@ pub(super) fn this_token_descr(&self) -> String {
|
|||||||
crate fn unexpected<T>(&mut self) -> PResult<'a, T> {
|
crate fn unexpected<T>(&mut self) -> PResult<'a, T> {
|
||||||
match self.expect_one_of(&[], &[]) {
|
match self.expect_one_of(&[], &[]) {
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
Ok(_) => unreachable!(),
|
// We can get `Ok(true)` from `recover_closing_delimiter`
|
||||||
|
// which is called in `expected_one_of_not_found`.
|
||||||
|
Ok(_) => FatalError.raise(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
src/test/ui/parser/issue-66357-unexpected-unreachable.rs
Normal file
14
src/test/ui/parser/issue-66357-unexpected-unreachable.rs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// The problem in #66357 was that the call trace:
|
||||||
|
//
|
||||||
|
// - parse_fn_block_decl
|
||||||
|
// - expect_or
|
||||||
|
// - unexpected
|
||||||
|
// - expect_one_of
|
||||||
|
// - expected_one_of_not_found
|
||||||
|
// - recover_closing_delimiter
|
||||||
|
//
|
||||||
|
// ended up bubbling up `Ok(true)` to `unexpected` which then used `unreachable!()`.
|
||||||
|
|
||||||
|
fn f() { |[](* }
|
||||||
|
//~^ ERROR expected one of `,` or `:`, found `(`
|
||||||
|
//~| ERROR expected one of `)`, `-`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
|
16
src/test/ui/parser/issue-66357-unexpected-unreachable.stderr
Normal file
16
src/test/ui/parser/issue-66357-unexpected-unreachable.stderr
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
error: expected one of `,` or `:`, found `(`
|
||||||
|
--> $DIR/issue-66357-unexpected-unreachable.rs:12:13
|
||||||
|
|
|
||||||
|
LL | fn f() { |[](* }
|
||||||
|
| ^ expected one of `,` or `:`
|
||||||
|
|
||||||
|
error: expected one of `)`, `-`, `_`, `box`, `mut`, `ref`, `|`, identifier, or path, found `*`
|
||||||
|
--> $DIR/issue-66357-unexpected-unreachable.rs:12:14
|
||||||
|
|
|
||||||
|
LL | fn f() { |[](* }
|
||||||
|
| -^ help: `)` may belong here
|
||||||
|
| |
|
||||||
|
| unclosed delimiter
|
||||||
|
|
||||||
|
error: aborting due to 2 previous errors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user