Skip to content

Commit

Permalink
Rollup merge of rust-lang#66361 - Centril:66357, r=pnkfelix
Browse files Browse the repository at this point in the history
parser: don't use `unreachable!()` in `fn unexpected`.

Fixes rust-lang#66357

r? @estebank
  • Loading branch information
JohnTitor committed Nov 14, 2019
2 parents 28c0e40 + dcd91d5 commit 8d05997
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@ impl<'a> Parser<'a> {
crate fn unexpected<T>(&mut self) -> PResult<'a, T> {
match self.expect_one_of(&[], &[]) {
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(),
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/parser/issue-66357-unexpected-unreachable.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions src/test/ui/parser/issue-66357-unexpected-unreachable.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8d05997

Please sign in to comment.