Skip to content

Compiler crash when matching generic enum #23151

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

Closed
bluecube opened this issue Mar 7, 2015 · 4 comments · Fixed by #23930
Closed

Compiler crash when matching generic enum #23151

bluecube opened this issue Mar 7, 2015 · 4 comments · Fixed by #23930
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@bluecube
Copy link

bluecube commented Mar 7, 2015

I tried this code:

enum Foo<T> {
    A(T),
    B
}

fn main() {
    let x = Foo::<u32>::A(14);
    let y = match x {
        Foo<T>::A(value) => value,
        Foo<T>::B => 7,
    };
    println!("{}", y);
}

and it gave me this message:

error.rs:9:9: 9:12 error: internal compiler error: ident only path should have been covered already
error.rs:9         Foo<T>::A(value) => value,
                   ^~~
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /tmp/portage/dev-lang/rust-1.0.0_alpha2/work/rustc-1.0.0-alpha.2/src/libsyntax/diagnostic.rs:129

I have git version of rust from package in funtoo linux.
When I tried the code at play.rust-lang.org the example produced compiler error, but not a crash.

Meta

rustc --version-verbose:

rustc 1.0.0-dev (built 2015-02-28)
binary: rustc
commit-hash: unknown
commit-date: unknown
build-date: 2015-02-28
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev

Backtrace:

   1:     0x7f894f434c20 - sys::backtrace::write::h6db1343660ca93a2KlC
   2:     0x7f894f45a900 - <unknown>
   3:     0x7f894f3a5d80 - rt::unwind::begin_unwind_inner::h734e583390472682RBL
   4:     0x7f894c8fa4e0 - <unknown>
   5:     0x7f894c8fa470 - diagnostic::SpanHandler::span_bug::ha4389e9b9cd26b0cvYE
   6:     0x7f894c91c950 - parse::parser::Parser<'a>::parse_pat::hbaca44ef1986f811wLL
   7:     0x7f894c9314c0 - parse::parser::Parser<'a>::parse_arm::h03dad4fde878481bYzL
   8:     0x7f894c926950 - parse::parser::Parser<'a>::parse_bottom_expr::hd51982e53d14adeaKwK
   9:     0x7f894c92c9a0 - parse::parser::Parser<'a>::parse_dot_or_call_expr::h73cc376278c09c13LPK
  10:     0x7f894c92f7c0 - parse::parser::Parser<'a>::parse_prefix_expr::h9ada9bffadff12ebpcL
  11:     0x7f894c930020 - parse::parser::Parser<'a>::parse_binops::hd3006072d5866dc6shL
  12:     0x7f894c930600 - parse::parser::Parser<'a>::parse_assign_expr::hb68dbae6fdb97b62imL
  13:     0x7f894c932420 - <unknown>
  14:     0x7f894c932640 - parse::parser::Parser<'a>::parse_stmt::h3a7a8bca0f5459e8v4L
  15:     0x7f894c93bff0 - <unknown>
  16:     0x7f894c91add0 - <unknown>
  17:     0x7f894c940630 - <unknown>
  18:     0x7f894c9352c0 - <unknown>
  19:     0x7f894c946830 - <unknown>
  20:     0x7f894c951b90 - parse::parser::Parser<'a>::parse_crate_mod::h1592f06e4a607835FlO
  21:     0x7f894c963d90 - parse::parse_crate_from_file::h71bb673ba4ce988fvNV
  22:     0x7f894fa4f920 - <unknown>
  23:     0x7f894fa29c10 - driver::phase_1_parse_input::h5a91fba8b70d831dQra
  24:     0x7f894fa26610 - driver::compile_input::ha5d27daf21872ba2Gba
  25:     0x7f894faf4b50 - run_compiler::he50deb5aedf688fcZbc
  26:     0x7f894faf3480 - <unknown>
  27:     0x7f894faf2370 - <unknown>
  28:     0x7f894f4b7bc0 - <unknown>
  29:     0x7f894f4b7bb0 - rust_try
  30:     0x7f894faf2670 - <unknown>
  31:     0x7f894f448650 - <unknown>
  32:     0x7f894a0acf40 - <unknown>
  33:     0x7f894f02b7d9 - clone
  34:                0x0 - <unknown>
@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 7, 2015
@shepmaster
Copy link
Member

@bluecube just in case you are stuck because of this, this is how that code would normally be written, and it does work. Note the lack of type definitions:

enum Foo<T> {
    A(T),
    B
}

fn main() {
    let x = Foo::A(14);
    let y = match x {
        Foo::A(value) => value,
        Foo::B        => 7,
    };
    println!("{}", y);
}

@bluecube
Copy link
Author

bluecube commented Mar 8, 2015

Thanks, @shepmaster.

@bombless
Copy link
Contributor

bombless commented Mar 8, 2015

enum Foo<T> {
    A(T),
    B
}

fn main() {
    let x = Foo::A::<u32>(14);
    let y = match x {
        Foo::A::<u32>(value) => value,
        Foo::B::<u32> => 7,
    };
    println!("{}", y);
}

This is also supported (for now, many people don't like this, let's see whether it will get removed in beta version).
The ICE should have been fixed in #22544, so later build won't have this problem.

@bluecube
Copy link
Author

You are right, after update of rust it doesn't crash..

bors added a commit that referenced this issue Apr 3, 2015
Fixes #22757
Fixes #22972
Fixes #23044
Fixes #23151
Fixes #23597
Fixes #23656
Fixes #23929
It also fixes some other corner cases in range patterns, like incorrect spans or not accepting global paths after `...`.

It passes `make check` but needs some additional tests (then it will fix #22546 as well), I'll write them today or tomorrow.
Manishearth added a commit to Manishearth/rust that referenced this issue Apr 3, 2015
Fixes rust-lang#22757
Fixes rust-lang#22972
Fixes rust-lang#23044
Fixes rust-lang#23151
Fixes rust-lang#23597
Fixes rust-lang#23656
Fixes rust-lang#23929
It also fixes some other corner cases in range patterns, like incorrect spans or not accepting global paths after `...`.

It passes `make check` but needs some additional tests (then it will fix rust-lang#22546 as well), I'll write them today or tomorrow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants