Skip to content

Compiler panic: 'internal error: entered unreachable code' in src/libsyntax/parse/parser.rs #60075

Closed
@Tiwalun

Description

@Tiwalun

I got an internal compiler error while compiling some code with a syntax error.

The error is in the final line of the match statement in the function parse.

use std::convert::{TryInto, TryFrom};
use std::io;
use byteorder::{LittleEndian, ReadBytesExt};

#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
pub enum DataWidth {
    One,
    Two,
    Four,
    Eight,
}

impl TryFrom<u8> for DataWidth {
    type Error = &'static str;

    fn try_from(from: u8) -> Result<Self, Self::Error> {
        use DataWidth::*;

        match from {
            1 => Ok(One),
            2 => Ok(Two),
            4 => Ok(Four),
            8 => Ok(Eight),
            _ => Err("Unsupported datawidth")
        }
    }
}


#[derive(Debug, PartialEq, Eq, Hash)]
pub struct QValue {
    pub value: u64,
    pub width: DataWidth,
}


impl QValue {
fn parse<R: io::Read>(bytes: &mut R, width: DataWidth) -> Option<QValue> {
    use DataWidth::*;

    let value = match width {
        One => {
            bytes.read_u8().ok()? as u64
        },
        Two => {
            bytes.read_u16::<LittleEndian>().ok()? as u64
        },
        Four => {
            bytes.read_u32::<LittleEndian>().ok()? as u64
        },
        Eight => { 
            bytes.read_u64::<LittleEndian>().ok()? as u64
        }
    });

    Some(QValue {
        value: value,
        width: width,
    })
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: incorrect close delimiter: `)`
  --> src/lib.rs:54:6
   |
38 | fn parse<R: io::Read>(bytes: &mut R, width: DataWidth) -> Option<QValue> {
   |                                                                          - un-closed delimiter
...
54 |     });
   |      ^ incorrect close delimiter

error: expected one of `.`, `;`, `?`, or an operator, found `}`
  --> src/lib.rs:54:6
   |
54 |     });
   |      ^ expected one of `.`, `;`, `?`, or an operator here

error: expected one of `async`, `const`, `crate`, `default`, `existential`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `;`
  --> src/lib.rs:54:7
   |
38 | fn parse<R: io::Read>(bytes: &mut R, width: DataWidth) -> Option<QValue> {
   |                                                                          - unclosed delimiter
...
54 |     });
   |       ^
   |       |
   |       help: `}` may belong here

thread 'rustc' panicked at 'internal error: entered unreachable code', src/libsyntax/parse/parser.rs:661:22
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: syntax::parse::parser::Parser::parse_fn_front_matter
   8: syntax::parse::parser::Parser::parse_impl_method
   9: syntax::parse::parser::Parser::parse_impl_item
  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
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.36.0-nightly (3c3d3c177 2019-04-17) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions