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 when matching integers against casted enum constants #24106

Closed
andersk opened this issue Apr 6, 2015 · 9 comments
Closed
Labels
E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@andersk
Copy link
Contributor

andersk commented Apr 6, 2015

I get “error: internal compiler error: unexpected panic” when running cargo test on andersk/image-rs@a9d74e9, which contains the image crate patched as follows. (I was trying to find an alternative to the unstable FromPrimitive.)

--- a/src/png/decoder.rs
+++ b/src/png/decoder.rs
@@ -242,9 +242,12 @@ impl<R: Read> PNGDecoder<R> {
             )))
         }

-        self.interlace_method = match FromPrimitive::from_u8(try!(try!(m.by_ref().bytes().next().ok_or(ImageError::ImageEnd)))) {
-            Some(method) => method,
-            None => return Err(ImageError::UnsupportedError(
+        const NONE_U8: u8 = InterlaceMethod::None as u8;
+        const ADAM7_U8: u8 = InterlaceMethod::Adam7 as u8;
+        self.interlace_method = match try!(try!(m.by_ref().bytes().next().ok_or(ImageError::ImageEnd))) {
+            NONE_U8 => InterlaceMethod::None,
+            ADAM7_U8 => InterlaceMethod::Adam7,
+            _ => return Err(ImageError::UnsupportedError(
                 "Unsupported interlace method.".to_string()
             ))
         };
$ rustc --version --verbose
rustc 1.0.0-nightly (083b8a404 2015-04-05) (built 2015-04-05)
binary: rustc
commit-hash: 083b8a40413eb3dfec7430150b8895f6c8bbafca
commit-date: 2015-04-05
build-date: 2015-04-05
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly
$ git clone https://github.com/andersk/image.git -b ice-non-constant-path
$ cd image
$ cargo test
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling byteorder v0.3.5
   Compiling glob v0.2.9
   Compiling libc v0.1.5
   Compiling rustc-serialize v0.3.12
   Compiling log v0.3.1
   Compiling rand v0.3.7
   Compiling num v0.1.22
   Compiling image v0.3.6 (file:///tmp/image)
src/png/decoder.rs:245:29: 245:56 error: non-constant path in constant expr
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'compare_list_exprs: type mismatch', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/_match.rs:238


Build failed, waiting for other jobs to finish...
src/png/decoder.rs:245:29: 245:56 error: non-constant path in constant expr
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'compare_list_exprs: type mismatch', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/_match.rs:238


Could not compile `image`.

To learn more, run the command again with --verbose.
$ RUST_BACKTRACE=1 cargo test
   Compiling image v0.3.6 (file:///tmp/image)
src/png/decoder.rs:245:29: 245:56 error: non-constant path in constant expr
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'compare_list_exprs: type mismatch', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/_match.rs:238

stack backtrace:
   1:     0x7f409eb1c7b8 - sys::backtrace::write::h4618bbda30a2c1fakHC
   2:     0x7f409eb47b87 - panicking::on_panic::h94b32ff0a2406463uUI
   3:     0x7f409ea7f893 - rt::unwind::begin_unwind_inner::h310b6bce2d1d1820CzI
   4:     0x7f409e0f232c - rt::unwind::begin_unwind::h13934619924931650302
   5:     0x7f409e23549e - trans::_match::compile_submatch_continue::h1d04a0fa292db3f4rsw
   6:     0x7f409e23181e - trans::_match::compile_submatch::hf239162a447365b4vmw
   7:     0x7f409e23b60f - trans::_match::trans_match_inner::h9fda511bd32f1e22gUw
   8:     0x7f409e18d2fc - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
   9:     0x7f409e18ba50 - trans::expr::trans_unadjusted::h85803b42d44a1ac7TXh
  10:     0x7f409e1431b4 - trans::expr::trans::h33635d14dc9ce441Blh
  11:     0x7f409e190543 - trans::expr::trans_rvalue_stmt_unadjusted::h0b3806dbe8a23414Bni
  12:     0x7f409e1419b9 - trans::expr::trans_into::h697e5a8350e86c68gfh
  13:     0x7f409e1408c6 - trans::controlflow::trans_stmt_semi::h956c9896cfc4a4efL5d
  14:     0x7f409e142515 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  15:     0x7f409e21958f - trans::base::trans_closure::hf8f2acf635294d9bQtt
  16:     0x7f409e12b4e6 - trans::base::trans_fn::hcf32337a6c531893zEt
  17:     0x7f409e12ce07 - trans::monomorphize::monomorphic_fn::h21abcb97c3717924Ytd
  18:     0x7f409e16ec3c - trans::callee::trans_fn_ref_with_substs::hd39a6e0257b1ea36Zbg
  19:     0x7f409e16cffb - trans::callee::trans_fn_ref::hae42401196387f572Zf
  20:     0x7f409e1842fd - trans::meth::trans_method_callee::h97933408a6916e9eEvy
  21:     0x7f409e1824a0 - trans::callee::trans_call_inner::h2971582447602048389
  22:     0x7f409e18cbaf - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  23:     0x7f409e18ba50 - trans::expr::trans_unadjusted::h85803b42d44a1ac7TXh
  24:     0x7f409e1431b4 - trans::expr::trans::h33635d14dc9ce441Blh
  25:     0x7f409e23a2f0 - trans::_match::trans_match_inner::h9fda511bd32f1e22gUw
  26:     0x7f409e18d2fc - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  27:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  28:     0x7f409e1408c6 - trans::controlflow::trans_stmt_semi::h956c9896cfc4a4efL5d
  29:     0x7f409e142515 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  30:     0x7f409e18d358 - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  31:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  32:     0x7f409e23b6b8 - trans::_match::trans_match_inner::h9fda511bd32f1e22gUw
  33:     0x7f409e18d2fc - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  34:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  35:     0x7f409e1408c6 - trans::controlflow::trans_stmt_semi::h956c9896cfc4a4efL5d
  36:     0x7f409e142515 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  37:     0x7f409e190e82 - trans::expr::trans_rvalue_stmt_unadjusted::h0b3806dbe8a23414Bni
  38:     0x7f409e1419b9 - trans::expr::trans_into::h697e5a8350e86c68gfh
  39:     0x7f409e1408c6 - trans::controlflow::trans_stmt_semi::h956c9896cfc4a4efL5d
  40:     0x7f409e142515 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  41:     0x7f409e21958f - trans::base::trans_closure::hf8f2acf635294d9bQtt
  42:     0x7f409e12b4e6 - trans::base::trans_fn::hcf32337a6c531893zEt
  43:     0x7f409e12ce07 - trans::monomorphize::monomorphic_fn::h21abcb97c3717924Ytd
  44:     0x7f409e16ec3c - trans::callee::trans_fn_ref_with_substs::hd39a6e0257b1ea36Zbg
  45:     0x7f409e16cffb - trans::callee::trans_fn_ref::hae42401196387f572Zf
  46:     0x7f409e1842fd - trans::meth::trans_method_callee::h97933408a6916e9eEvy
  47:     0x7f409e1824a0 - trans::callee::trans_call_inner::h2971582447602048389
  48:     0x7f409e18cbaf - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  49:     0x7f409e18ba50 - trans::expr::trans_unadjusted::h85803b42d44a1ac7TXh
  50:     0x7f409e1431b4 - trans::expr::trans::h33635d14dc9ce441Blh
  51:     0x7f409e23a2f0 - trans::_match::trans_match_inner::h9fda511bd32f1e22gUw
  52:     0x7f409e18d2fc - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  53:     0x7f409e18bb64 - trans::expr::trans_unadjusted::h85803b42d44a1ac7TXh
  54:     0x7f409e1431b4 - trans::expr::trans::h33635d14dc9ce441Blh
  55:     0x7f409e140c11 - trans::base::init_local::hd82fb8d63aae5490NMs
  56:     0x7f409e142542 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  57:     0x7f409e18e1f1 - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  58:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  59:     0x7f409e1408c6 - trans::controlflow::trans_stmt_semi::h956c9896cfc4a4efL5d
  60:     0x7f409e142515 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  61:     0x7f409e21958f - trans::base::trans_closure::hf8f2acf635294d9bQtt
  62:     0x7f409e12b4e6 - trans::base::trans_fn::hcf32337a6c531893zEt
  63:     0x7f409e12ce07 - trans::monomorphize::monomorphic_fn::h21abcb97c3717924Ytd
  64:     0x7f409e16ec3c - trans::callee::trans_fn_ref_with_substs::hd39a6e0257b1ea36Zbg
  65:     0x7f409e1867e1 - trans::meth::trans_method_callee::h97933408a6916e9eEvy
  66:     0x7f409e1824a0 - trans::callee::trans_call_inner::h2971582447602048389
  67:     0x7f409e18cbaf - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  68:     0x7f409e18ba50 - trans::expr::trans_unadjusted::h85803b42d44a1ac7TXh
  69:     0x7f409e1431b4 - trans::expr::trans::h33635d14dc9ce441Blh
  70:     0x7f409e23a2f0 - trans::_match::trans_match_inner::h9fda511bd32f1e22gUw
  71:     0x7f409e18d2fc - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  72:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  73:     0x7f409e25649f - trans::_match::mk_binding_alloca::h1923058631601932975
  74:     0x7f409e140b3c - trans::base::init_local::hd82fb8d63aae5490NMs
  75:     0x7f409e142542 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  76:     0x7f409e21958f - trans::base::trans_closure::hf8f2acf635294d9bQtt
  77:     0x7f409e12b4e6 - trans::base::trans_fn::hcf32337a6c531893zEt
  78:     0x7f409e12cd62 - trans::monomorphize::monomorphic_fn::h21abcb97c3717924Ytd
  79:     0x7f409e16ec3c - trans::callee::trans_fn_ref_with_substs::hd39a6e0257b1ea36Zbg
  80:     0x7f409e16cffb - trans::callee::trans_fn_ref::hae42401196387f572Zf
  81:     0x7f409e16aa5d - trans::callee::trans::he76dd5bb3190a87djPf
  82:     0x7f409e180738 - trans::callee::trans_call_inner::h13603331029633186103
  83:     0x7f409e18ddf3 - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  84:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  85:     0x7f409e23b6b8 - trans::_match::trans_match_inner::h9fda511bd32f1e22gUw
  86:     0x7f409e18d2fc - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  87:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  88:     0x7f409e1428b2 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  89:     0x7f409e21958f - trans::base::trans_closure::hf8f2acf635294d9bQtt
  90:     0x7f409e12b4e6 - trans::base::trans_fn::hcf32337a6c531893zEt
  91:     0x7f409e12cd62 - trans::monomorphize::monomorphic_fn::h21abcb97c3717924Ytd
  92:     0x7f409e16ec3c - trans::callee::trans_fn_ref_with_substs::hd39a6e0257b1ea36Zbg
  93:     0x7f409e16cffb - trans::callee::trans_fn_ref::hae42401196387f572Zf
  94:     0x7f409e16aa5d - trans::callee::trans::he76dd5bb3190a87djPf
  95:     0x7f409e180738 - trans::callee::trans_call_inner::h13603331029633186103
  96:     0x7f409e18ddf3 - trans::expr::trans_rvalue_dps_unadjusted::h5cec7ac55049a34amti
  97:     0x7f409e141848 - trans::expr::trans_into::h697e5a8350e86c68gfh
  98:     0x7f409e1428b2 - trans::controlflow::trans_block::h4d71ce810e64920fH6d
  99:     0x7f409e21958f - trans::base::trans_closure::hf8f2acf635294d9bQtt
  100:     0x7f409e12b4e6 - trans::base::trans_fn::hcf32337a6c531893zEt
 ... <frames omitted>

Build failed, waiting for other jobs to finish...
[another copy of the same backtrace]

Could not compile `image`.

To learn more, run the command again with --verbose.
@andersk
Copy link
Contributor Author

andersk commented Apr 6, 2015

Here’s a minimized test case.

$ rustc --version --verbose
rustc 1.0.0-nightly (083b8a404 2015-04-05) (built 2015-04-05)
binary: rustc
commit-hash: 083b8a40413eb3dfec7430150b8895f6c8bbafca
commit-date: 2015-04-05
build-date: 2015-04-05
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly
$ cat foo.rs
#![crate_type = "rlib"]

enum E { E0 = 0, E1 = 1 }
const E0_U8: u8 = E::E0 as u8;
const E1_U8: u8 = E::E1 as u8;

pub fn go<T>() {
    match 0 {
        E0_U8 => (),
        E1_U8 => (),
        _ => (),
    }
}

$ cat bar.rs
extern crate foo;

fn main() {
    foo::go::<()>();
}

$ rustc foo.rs
$ rustc bar.rs -L .
foo.rs:4:19: 4:30 error: non-constant path in constant expr
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'compare_list_exprs: type mismatch', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/_match.rs:238

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 6, 2015
abhijeetbhagat added a commit to abhijeetbhagat/glacier that referenced this issue Nov 3, 2015
@steveklabnik
Copy link
Member

This no longer ICEs

@steveklabnik steveklabnik added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Nov 6, 2015
@TheNeikos
Copy link
Contributor

I would like to have a go at this issue since it is marked E-easy.

I do wonder though how I would go about making a test case.
This only panics if you use two seperate files.

@mitaa
Copy link
Contributor

mitaa commented Nov 25, 2015

@TheNeikos
You can put foo.rs in test/auxiliary and use use // aux-build:foo.rs in bar.rs, like demonstrated here cebb118

(aux-build should probably be added to COMPILER_TESTS.md)

@TheNeikos
Copy link
Contributor

So what I found out that happens:

src/librustc_trans/trans/_match.rs:243 gets a None value

I added a println! to get an idea of what is going on:

println!("{:?} =?= {:?}", self.0, other.0); 

The output of that println is: expr(28: E::E0 as u8) =?= expr(34: E::E1 as u8)

Where as the error that occurs through which a None is returned is:
"non-constant path in constant expression"

I am not sure what I should check out first, any pointers?

@jonas-schievink
Copy link
Contributor

This still ICEs and isn't E-needstest and probably not E-easy either.

@alexcrichton alexcrichton removed E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. labels Nov 25, 2015
@TheNeikos
Copy link
Contributor

Haha, alright, well if it is indeed more complicated, I will step back from it.

@brson
Copy link
Contributor

brson commented Jul 19, 2016

Triage: still repros. Error shows a bit more

$ rustc bar.rs -L .
foo.rs:5:19: 5:30 error: unimplemented constant expression: enum variants
foo.rs:5
                           ^~~~~~~~~~~
error: internal compiler error: ../src/librustc_trans\_match.rs:244: compare_list_exprs: type mismatch
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
thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:619
note: Run with `RUST_BACKTRACE=1` for a backtrace.

@cyplo
Copy link
Contributor

cyplo commented Oct 22, 2016

The minimized example does compile without any error for me on rustc 1.12.1 (d4f3940 2016-10-19)

@arielb1 arielb1 added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 24, 2016
euclio added a commit to euclio/rust that referenced this issue May 5, 2017
frewsxcv added a commit to frewsxcv/rust that referenced this issue May 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

10 participants