Skip to content

Internal compiler error on malformed match arm pattern #54379

Closed
@mcduke

Description

@mcduke

The compiler panics when trying to compile the following code:

pub struct MyStruct {
    pub value: u64,
    pub s1: Option<String>,
}

fn main() {
    let v = vec![];

    for thing in v.iter() {
        match thing {
            MyStruct { .., Some(_) } => {}
            _ => {}
        }
    }
}

Expectation: A compiler error complaining about the malformed match guard pattern.

Actual result: A compiler panic

error: internal compiler error: Error constructed but not emitted

thread 'main' panicked at 'explicit panic', librustc_errors\diagnostic_builder.rs:308:13

Meta

This happens with both the lastest stable and nightly versions:

$ rustc +nightly --version --verbose
rustc 1.30.0-nightly (20dc0c507 2018-09-19)
binary: rustc
commit-hash: 20dc0c50704ba1fc8c56a88ae2bf05ddb3e419bc
commit-date: 2018-09-19
host: x86_64-pc-windows-msvc
release: 1.30.0-nightly
LLVM version: 8.0

$ rustc +stable --version --verbose
rustc 1.29.0 (aa3ca1994 2018-09-11)
binary: rustc
commit-hash: aa3ca1994904f2e056679fce1f185db8c7ed2703
commit-date: 2018-09-11
host: x86_64-pc-windows-msvc
release: 1.29.0
LLVM version: 7.0

Backtrace (nightly):

$ rustc +nightly src\main.rs
error: internal compiler error: Error constructed but not emitted

thread 'main' panicked at 'explicit panic', librustc_errors\diagnostic_builder.rs:308:13
stack backtrace:
   0: <std::sync::barrier::BarrierWaitResult as core::fmt::Debug>::fmt
   1: std::io::error::Error::get_ref
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: std::panicking::rust_panic_with_hook
   5: <rustc_errors::diagnostic::SubDiagnostic as core::fmt::Debug>::fmt
   6: <rustc_errors::diagnostic_builder::DiagnosticBuilder<'a> as core::ops::drop::Drop>::drop
   7: syntax::parse::parser::Parser::parse_expr
   8: syntax::parse::parser::Parser::parse_pat
   9: syntax::parse::parser::Parser::parse_expr
  10: syntax::parse::parser::Parser::parse_expr
  11: syntax::parse::parser::Parser::parse_async_block
  12: syntax::parse::parser::Parser::mk_mac_expr
  13: syntax::parse::parser::Parser::mk_mac_expr
  14: syntax::parse::parser::Parser::parse_tokens
  15: syntax::parse::parser::Parser::parse_tokens
  16: syntax::parse::parser::Parser::parse_stmt
  17: syntax::parse::parser::Parser::parse_block
  18: syntax::parse::parser::Parser::parse_block
  19: syntax::parse::parser::Parser::parse_block
  20: syntax::parse::parser::Parser::parse_tokens
  21: syntax::parse::parser::Parser::mk_mac_expr
  22: syntax::parse::parser::Parser::mk_mac_expr
  23: syntax::parse::parser::Parser::parse_tokens
  24: syntax::parse::parser::Parser::parse_tokens
  25: syntax::parse::parser::Parser::parse_stmt
  26: syntax::parse::parser::Parser::parse_block
  27: syntax::parse::parser::Parser::parse_block
  28: syntax::parse::parser::Parser::parse_block
  29: syntax::parse::parser::Parser::parse_block
  30: syntax::parse::parser::Parser::default_submod_path
  31: syntax::parse::parser::Parser::default_submod_path
  32: syntax::parse::parser::Parser::parse_item
  33: syntax::parse::parser::Parser::parse_visibility
  34: syntax::parse::parser::Parser::parse_crate_mod
  35: syntax::parse::parse_crate_from_file
  36: rustc_driver::target_features::add_configuration
  37: rustc_driver::target_features::add_configuration
  38: rustc_driver::driver::phase_1_parse_input
  39: rustc_driver::driver::compile_input
  40: rustc_driver::run_compiler
  41: rustc_driver::target_features::add_configuration
  42: rustc_driver::run_compiler
  43: rustc_driver::target_features::add_configuration
  44: _rust_maybe_catch_panic
  45: rustc_driver::profile::dump
  46: rustc_driver::main
  47: <unknown>
  48: std::panicking::update_panic_count
  49: _rust_maybe_catch_panic
  50: std::rt::lang_start_internal
  51: <unknown>
  52: <unknown>
  53: BaseThreadInitThunk
  54: RtlUserThreadStart
error: aborting due to previous error

Backtrace (stable):

$ rustc +stable src\main.rs
error: internal compiler error: Error constructed but not emitted

thread 'main' panicked at 'explicit panic', librustc_errors\diagnostic_builder.rs:250:13
stack backtrace:
   0: <std::sync::mpsc::RecvTimeoutError as core::fmt::Debug>::fmt
   1: <std::sys::windows::dynamic_lib::DynamicLibrary as core::ops::drop::Drop>::drop
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: std::panicking::rust_panic_with_hook
   5: <rustc_errors::emitter::ColorConfig as core::fmt::Debug>::fmt
   6: <rustc_errors::diagnostic_builder::DiagnosticBuilder<'a> as core::ops::drop::Drop>::drop
   7: syntax::parse::parser::Parser::parse_expr
   8: syntax::parse::parser::Parser::parse_pat
   9: syntax::parse::parser::Parser::parse_expr
  10: syntax::parse::parser::Parser::parse_expr
  11: syntax::parse::parser::Parser::parse_async_block
  12: syntax::parse::parser::Parser::mk_mac_expr
  13: syntax::parse::parser::Parser::mk_mac_expr
  14: syntax::parse::parser::Parser::parse_tokens
  15: syntax::parse::parser::Parser::parse_tokens
  16: syntax::parse::parser::Parser::parse_stmt
  17: syntax::parse::parser::Parser::parse_block
  18: syntax::parse::parser::Parser::parse_block
  19: syntax::parse::parser::Parser::parse_block
  20: syntax::parse::parser::Parser::parse_tokens
  21: syntax::parse::parser::Parser::mk_mac_expr
  22: syntax::parse::parser::Parser::mk_mac_expr
  23: syntax::parse::parser::Parser::parse_tokens
  24: syntax::parse::parser::Parser::parse_tokens
  25: syntax::parse::parser::Parser::parse_stmt
  26: syntax::parse::parser::Parser::parse_block
  27: syntax::parse::parser::Parser::parse_block
  28: syntax::parse::parser::Parser::parse_block
  29: syntax::parse::parser::Parser::parse_block
  30: syntax::parse::parser::Parser::default_submod_path
  31: syntax::parse::parser::Parser::default_submod_path
  32: syntax::parse::parser::Parser::parse_item
  33: syntax::parse::parser::Parser::parse_visibility
  34: syntax::parse::parser::Parser::parse_crate_mod
  35: syntax::parse::parse_crate_from_file
  36: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  37: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  38: rustc_driver::driver::phase_1_parse_input
  39: rustc_driver::driver::compile_input
  40: rustc_driver::run_compiler
  41: <rustc_driver::profile::trace::Query as core::fmt::Debug>::fmt
  42: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  43: _rust_maybe_catch_panic
  44: rustc_driver::profile::dump
  45: rustc_driver::main
  46: <unknown>
  47: std::panicking::update_panic_count
  48: _rust_maybe_catch_panic
  49: std::rt::lang_start_internal
  50: <unknown>
  51: <unknown>
  52: BaseThreadInitThunk
  53: RtlUserThreadStart
error: aborting due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions