Skip to content

impossible case reached: bad combination of types for cast #21397

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
mhobbs-8B opened this issue Jan 19, 2015 · 3 comments · Fixed by #25038
Closed

impossible case reached: bad combination of types for cast #21397

mhobbs-8B opened this issue Jan 19, 2015 · 3 comments · Fixed by #25038
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@mhobbs-8B
Copy link

Running Arch Linux: 3.17.6-1-ARCH #1 SMP PREEMPT Sun Dec 7 23:43:32 UTC 2014 x86_64 GNU/Linux

rustc 1.0.0-nightly (f4f10db 2015-01-17 20:31:08 +0000)
binary: rustc
commit-hash: f4f10db
commit-date: 2015-01-17 20:31:08 +0000
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly

Here's the line that caused the error:
pub static mut SOCKS_HOST: *const str = 0 as *const str;

backtrace:

thread 'rustc' panicked at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libsyntax/diagnostic.rs:126

stack backtrace:
   1:     0x7f81445c3c90 - sys::backtrace::write::hda88ebe91818f572tXt
   2:     0x7f81445e5b90 - failure::on_fail::h9fbfe25f5b38e775qeA
   3:     0x7f8144554300 - rt::unwind::begin_unwind_inner::h1bd92865247a942cjTz
   4:     0x7f813efd7770 - rt::unwind::begin_unwind::h15336451338054780329
   5:     0x7f813efd7700 - diagnostic::SpanHandler::span_bug::h110bf60630d186b1VoF
   6:     0x7f814293e690 - session::Session::impossible_case::h7839f1024fe36b1etFp
   7:     0x7f8143d5eb50 - trans::consts::const_expr_unadjusted::he1dcbfb2818dd7e8Gfo
   8:     0x7f8143d5cdb0 - trans::consts::const_expr::h734b9de8ebda8b92N4n
   9:     0x7f8143c977b0 - trans::base::get_item_val::h8df99413e1d50374a3u
  10:     0x7f8143d64450 - trans::consts::trans_static::hfe38a6a23470d6e4UJo
  11:     0x7f8143c952c0 - trans::base::trans_item::h25a1b35201e5520bCyu
  12:     0x7f8143d7d320 - trans::base::trans_mod::h63dc8a5716cd3e9eeEu
  13:     0x7f8143c952c0 - trans::base::trans_item::h25a1b35201e5520bCyu
  14:     0x7f8143d804d0 - trans::base::trans_crate::hcee70ebbe1e36918juv
  15:     0x7f8144b26a70 - driver::phase_4_translate_to_llvm::h1d3249612b78766ewOa
  16:     0x7f8144b06960 - driver::compile_input::h9092b12341e3a857Cba
  17:     0x7f8144bc8340 - run_compiler::h62323e6edb706ae8nac
  18:     0x7f8144bc6ab0 - thunk::F.Invoke<A, R>::invoke::h12018745279237426453
  19:     0x7f8144bc5a10 - rt::unwind::try::try_fn::h1504517046915204584
  20:     0x7f814464cc00 - rust_try_inner
  21:     0x7f814464cbf0 - rust_try
  22:     0x7f8144bc5cc0 - thunk::F.Invoke<A, R>::invoke::h3360625291245025634
  23:     0x7f81445d37f0 - sys::thread::thread_start::h4faa993964f784ad5Nw
  24:     0x7f813e7f3250 - start_thread
  25:     0x7f8144205219 - clone
  26:                0x0 - <unknown>
@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jan 19, 2015
@nathantypanski
Copy link
Contributor

This is falling through the match expression on /src/librustc_trans/trans/consts.rs#L518-L521

&'static str -> *const str panics also:

ice.rs:1:35: 1:51 error: internal compiler error: impossible case reached: bad combination of types for cast
ice.rs:1 pub static mut fail: *const str = "" as *const str;
                                           ^~~~~~~~~~~~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /home/nathan/prj/rust/rust/src/libsyntax/diagnostic.rs:126

stack backtrace:
   1:     0x7ffbb1e686d0 - sys::backtrace::write::hfb11ddfd0e7f0658eRt
   2:     0x7ffbb1e8a5a0 - failure::on_fail::hbcb8cd329aec6ff6J4z
   3:     0x7ffbb1df8e20 - rt::unwind::begin_unwind_inner::haafd3e91071bc3e1XJz
   4:     0x7ffbaca18810 - rt::unwind::begin_unwind::h6185406380551317121
   5:     0x7ffbaca187a0 - diagnostic::SpanHandler::span_bug::h6c67dceaab6289dcEpF
   6:     0x7ffbb01eb3b0 - session::Session::impossible_case::h3d86ed69bec12c961fp
   7:     0x7ffbb16033e0 - trans::consts::const_expr_unadjusted::h7bbb3fd0d30587f7ado
   8:     0x7ffbb1601640 - trans::consts::const_expr::h62680ecd661789d2h2n
   9:     0x7ffbb153bfe0 - trans::base::get_item_val::heeb56e6127c59fe8IYu
  10:     0x7ffbb1608ce0 - trans::consts::trans_static::h24dedd3ba4c51141fHo
  11:     0x7ffbb1539af0 - trans::base::trans_item::h386d32b9df74fe59iuu
  12:     0x7ffbb1624ce0 - trans::base::trans_crate::h777b6fde95f212b0Lpv
  13:     0x7ffbb23d2d40 - driver::phase_4_translate_to_llvm::he23925e56602061eTNa
  14:     0x7ffbb23b2c30 - driver::compile_input::hb4efdf66e0f650f5Cba
  15:     0x7ffbb247d9a0 - run_compiler::h9d3e14b442c4d365l9b
  16:     0x7ffbb247c110 - thunk::F.Invoke<A, R>::invoke::h14209112065483412921
  17:     0x7ffbb247b070 - rt::unwind::try::try_fn::h1021622462190646014
  18:     0x7ffbb1efa120 - rust_try_inner
  19:     0x7ffbb1efa110 - rust_try
  20:     0x7ffbb247b320 - thunk::F.Invoke<A, R>::invoke::h14035172896832106325
  21:     0x7ffbb1e78210 - sys::thread::thread_start::he2d36a2cbcaf629dzGw
  22:     0x7ffbac233250 - start_thread
  23:     0x7ffbb1aa9219 - clone
  24:                0x0 - <unknown>

I believe the case happening here is (expr::cast_integral, expr::cast_other), based on
a similar, but not quite equivalent, failure with the following code:

fn main() {
    let mut fail: *const str = 0 as *const str;
}
error: internal compiler error: translating unsupported cast: usize (cast_integral) -> *const str (cast_other)
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /home/nathan/prj/rust/rust/src/libsyntax/diagnostic.rs:185

stack backtrace:
   1:     0x7f373294c6d0 - sys::backtrace::write::hfb11ddfd0e7f0658eRt
   2:     0x7f373296e5a0 - failure::on_fail::hbcb8cd329aec6ff6J4z
   3:     0x7f37328dce20 - rt::unwind::begin_unwind_inner::haafd3e91071bc3e1XJz
   4:     0x7f372d4fc810 - rt::unwind::begin_unwind::h6185406380551317121
   5:     0x7f372d4fd0b0 - diagnostic::Handler::bug::h22dd58059bfb9b94EvF
   6:     0x7f3730a00710 - session::Session::bug::ha3b9a2f7768518e0Ucp
   7:     0x7f373209a930 - trans::expr::trans_imm_cast::h6237da60fefe9c376ek
   8:     0x7f373207e5a0 - trans::expr::trans_unadjusted::he8968cac83a4541c4ii
   9:     0x7f3732037ed0 - trans::expr::trans::h8455960f4e8fd42dCBh
  10:     0x7f3732036d30 - trans::expr::trans_into::h83699b23dbd8bfcf8xh
  11:     0x7f37321378a0 - trans::_match::mk_binding_alloca::h10237289352598662242
  12:     0x7f37320363a0 - trans::base::init_local::h919eb93f221f2a7065s
  13:     0x7f3732037330 - trans::controlflow::trans_block::h2d166cd595ca56b6Z2d
  14:     0x7f3732101a70 - trans::base::trans_closure::h7bc248b8281c1222wWt
  15:     0x7f3732022930 - trans::base::trans_fn::h79df99adfc5fa22276t
  16:     0x7f373201daf0 - trans::base::trans_item::h386d32b9df74fe59iuu
  17:     0x7f3732108ce0 - trans::base::trans_crate::h777b6fde95f212b0Lpv
  18:     0x7f3732eb6d40 - driver::phase_4_translate_to_llvm::he23925e56602061eTNa
  19:     0x7f3732e96c30 - driver::compile_input::hb4efdf66e0f650f5Cba
  20:     0x7f3732f619a0 - run_compiler::h9d3e14b442c4d365l9b
  21:     0x7f3732f60110 - thunk::F.Invoke<A, R>::invoke::h14209112065483412921
  22:     0x7f3732f5f070 - rt::unwind::try::try_fn::h1021622462190646014
  23:     0x7f37329de120 - rust_try_inner
  24:     0x7f37329de110 - rust_try
  25:     0x7f3732f5f320 - thunk::F.Invoke<A, R>::invoke::h14035172896832106325
  26:     0x7f373295c210 - sys::thread::thread_start::he2d36a2cbcaf629dzGw
  27:     0x7f372cd17250 - start_thread
  28:     0x7f373258d219 - clone
  29:                0x0 - <unknown>

The above bugs out somewhere in src/librustc_trans/trans/expr.rs#L2047-L2061

Should either of these casts actually succeed?

@shepmaster
Copy link
Member

Saw a similar case:

static mut static_trait: *mut (Trait + 'static) = 0 as *mut _;
pub trait Trait {}
pub fn main() {}

on rustc 1.0.0-dev (342ab53bf 2015-02-15 12:20:31 +0000)

@tamird
Copy link
Contributor

tamird commented Apr 22, 2015

Triage: still ICEs.

fn main() {
    let mut fail: *const str = 0 as *const str;
}

and

static mut static_trait: *mut (Trait + 'static) = 0 as *mut _;
pub trait Trait {}
pub fn main() {}

bluss pushed a commit to bluss/rust that referenced this issue May 1, 2015
Fixes an ICE on casting *const [T] to *const T and similar cases.

Fixes rust-lang#21397
Fixes rust-lang#22955
bluss pushed a commit to bluss/rust that referenced this issue May 1, 2015
Fixes an ICE on casting *const T to *const [T] and similar cases.

Fixes rust-lang#21397
Fixes rust-lang#22955
bluss pushed a commit to bluss/rust that referenced this issue May 1, 2015
Fixes ICEs where non-fat pointers and scalars are cast to fat pointers,

Fixes rust-lang#21397
Fixes rust-lang#22955

Fix
bluss pushed a commit to bluss/rust that referenced this issue May 1, 2015
Fixes ICEs where non-fat pointers and scalars are cast to fat pointers,

Fixes rust-lang#21397
Fixes rust-lang#22955
Fixes rust-lang#23237
Fixes rust-lang#24100
bors added a commit that referenced this issue May 2, 2015
typeck: Make sure casts from other types to fat pointers are illegal

Fixes ICEs where non-fat pointers and scalars are cast to fat pointers,

Fixes #21397
Fixes #22955
Fixes #23237
Fixes #24100
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.

5 participants