Skip to content

Internal compiler error when matching integers against casted enum constants #24106

Closed
@andersk

Description

@andersk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions