rust-lang/rust

ICE on "internal error: entered unreachable code"

dwrensha opened this issue · 4 comments

I'm seeing an internal compiler error on the following input (found by fuzz-rustc):

impl W <s(f;Y(;]
error: this file contains an un-closed delimiter
 --> main.rs:1:18
  |
1 | impl W <s(f;Y(;]
  |          -       ^
  |          |
  |          un-closed delimiter

error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `;`
 --> main.rs:1:12
  |
1 | impl W <s(f;Y(;]
  |            ^ expected one of 7 possible tokens here

error: expected one of `!`, `&&`, `&`, `(`, `)`, `*`, `+`, `,`, `->`, `...`, `::`, `<`, `>`, `?`, `[`, `_`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, or lifetime, found `;`
 --> main.rs:1:15
  |
1 | impl W <s(f;Y(;]
  |              -^ help: `)` may belong here
  |              |
  |              unclosed delimiter

thread 'rustc' panicked at 'internal error: entered unreachable code', src/libsyntax/parse/parser.rs:565:22
stack backtrace:
   0: std::panicking::default_hook::{{closure}}
   1: std::panicking::default_hook
   2: rustc::util::common::panic_hook
   3: std::panicking::rust_panic_with_hook
   4: std::panicking::begin_panic
   5: syntax::parse::parser::Parser::expect_gt
   6: syntax::parse::parser::Parser::parse_path_segment
   7: syntax::parse::parser::Parser::parse_path_segments
   8: syntax::parse::parser::Parser::parse_path
   9: syntax::parse::parser::Parser::parse_ty_common
  10: syntax::parse::parser::Parser::parse_item_implementation
  11: syntax::parse::parser::Parser::parse_item_
  12: syntax::parse::parser::Parser::parse_item
  13: syntax::parse::parser::Parser::parse_mod_items
  14: syntax::parse::parser::Parser::parse_crate_mod
  15: syntax::parse::parse_crate_from_file
  16: rustc_interface::passes::parse::{{closure}}
  17: rustc::util::common::time
  18: rustc_interface::passes::parse
  19: rustc_interface::queries::Query<T>::compute
  20: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::parse
  21: rustc_interface::interface::run_compiler_in_existing_thread_pool
  22: std::thread::local::LocalKey<T>::with
  23: scoped_tls::ScopedKey<T>::set
  24: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
end of query stack
error: aborting due to 3 previous errors


error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.38.0-nightly (4560cb830 2019-07-28) running on x86_64-apple-darwin

This error does not occur on stable or beta, nor on a nightly from last week.

The panic is being thrown from here:

Ok(_) => unreachable!(),

That code assumes that self.expect_one_of(&[], &[]) will always return Err(_). However, in this case expect_one_of() calls expected_one_of_not_found(), which returns Ok(_) from here:

return Ok(recovered);

Seems fixed in the latest nightly(playground), marked as E-needstest

I'll add a test for this