Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal compiler error on malformed match arm pattern #54379

Closed
mcduke opened this issue Sep 20, 2018 · 8 comments
Closed

Internal compiler error on malformed match arm pattern #54379

mcduke opened this issue Sep 20, 2018 · 8 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@mcduke
Copy link

mcduke commented Sep 20, 2018

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
@mcduke
Copy link
Author

mcduke commented Sep 20, 2018

Simplified my example some more, this still makes the compiler panic:

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

fn main() {
    let thing = MyStruct { s1: None };

    match thing {
        MyStruct { .., Some(_) } => {},
        _ => {}
    }
}

Playground link

@estebank
Copy link
Contributor

It happens within parse_pat_fields.

It seems to me that the following err binding

let mut err = self.fatal(&format!("expected `}}`, found `{}`", token_str));

can be left created but not cancelled or emitted in the following code branch

if let Some(mut delayed_err) = delayed_err {
delayed_err.emit();
return Err(err);
} else {

@estebank estebank added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-help-wanted Call for participation: Help is requested to fix this issue. labels Sep 20, 2018
@raventid
Copy link
Contributor

Internal compiler error seems interesting, I'll take this.

@cipherself
Copy link
Contributor

@raventid Hi Julian, are you working on this?

@raventid
Copy link
Contributor

raventid commented Oct 6, 2018

@muattiyah, took a pause, will do it in next few days. So, the answer is yes.

@cipherself
Copy link
Contributor

@raventid Alright, thanks. Good luck 👍

@dsciarra
Copy link
Contributor

dsciarra commented Oct 7, 2018

I saw no activity for a couple of weeks and I started working in parallel on this. I think I have a fix...

pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 9, 2018
Fix internal compiler error on malformed match arm pattern.

Issue: rust-lang#54379
@ZerothLaw
Copy link

Looks like the fix was merged. Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants