Skip to content

rustc compiler panic on toy example involving Deref coercion of a &'static reference #25901

Closed
@lorenzb

Description

@lorenzb

When I try to compile the following code, rustc crashes.
I tried this code:

use std::ops::Deref;

struct DerefExample {
    value: char
}

impl Deref for DerefExample {
    type Target = char;

    fn deref<'a>(&'a self) -> &'a char {
        &self.value
    }
}

fn main() {
    let x: &char = &DerefExample { value: 'a' };
}

I expected to see this happen: rustc should compile the program

Instead, this happened: rustc crashed

Meta

The playground (both nightly and stable) is also affected.

My local version of rustc:
rustc --version --verbose:
rustc 1.0.0 (a59de37 2015-05-13) (built 2015-05-14)
binary: rustc
commit-hash: a59de37
commit-date: 2015-05-13
build-date: 2015-05-14
host: x86_64-apple-darwin
release: 1.0.0

Backtrace:

$ RUST_BACKTRACE=1 rustc crash.rs
crash.rs:16:9: 16:10 warning: unused variable: `x`, #[warn(unused_variables)] on by default
crash.rs:16     let x: &char = &DerefExample { value: 'a' };
                    ^
{ i32 } { i32 97 }
i8* undef
error: internal compiler error: const expr(37: &DerefExample{value: 'a',}) of type &'static char has size 4 instead of 8
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>', /Users/rustbuild/src/rust-buildbot/slave/stable-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:209

stack backtrace:
   1:        0x108e4fe7f - sys::backtrace::write::h7807ec07859fb503t1r
   2:        0x108e584b2 - panicking::on_panic::ha0ed2b9b562a7f9ctZv
   3:        0x108e14e35 - rt::unwind::begin_unwind_inner::hbfb8d99cb52be7a1cHv
   4:        0x10860043e - rt::unwind::begin_unwind::h14482673826369992638
   5:        0x108600be2 - diagnostic::Handler::bug::h3b0624d9fbca0a0bgwB
   6:        0x1063b7ee7 - session::Session::bug::hcdda6088c808dbb26Dq
   7:        0x105f0010a - trans::consts::const_expr::h97680e491db58226ovs
   8:        0x105f5ac19 - trans::consts::get_const_expr_as_global::haf67342c964c0a2bzss
   9:        0x105ecf10a - trans::expr::trans::h1978f8d98b53e4e9gdA
  10:        0x105f71810 - trans::expr::trans_into::hbb46bcc22ed210c3X6z
  11:        0x105ff54f1 - trans::_match::mk_binding_alloca::h6803792453219144123
  12:        0x105ee0479 - trans::base::init_local::h34081fe700fb2b37OVg
  13:        0x105ef0ea3 - trans::controlflow::trans_block::hdf65bd89d5d3fafb02u
  14:        0x105eefb55 - trans::base::trans_closure::h41cb738fdafdcb78LCh
  15:        0x105ef17ee - trans::base::trans_fn::hbccbee21cfd23d2atNh
  16:        0x105ef4d58 - trans::base::trans_item::hae807f8e0cfc6665Fbi
  17:        0x105f03ba2 - trans::base::trans_crate::h2f3789dec4e60e5cF0i
  18:        0x10598c27e - driver::phase_4_translate_to_llvm::h561d8971e5091942hOa
  19:        0x105964204 - driver::compile_input::hf0607b3d1fd498bcQba
  20:        0x105a2c5a3 - run_compiler::he7a5311c755081d7z4b
  21:        0x105a2a0ca - boxed::F.FnBox<A>::call_box::h5234503372052129763
  22:        0x105a29567 - rt::unwind::try::try_fn::h4031265711883657142
  23:        0x108ed9508 - rust_try_inner
  24:        0x108ed94f5 - rust_try
  25:        0x105a29840 - boxed::F.FnBox<A>::call_box::h1044299548107784679
  26:        0x108e56ffd - sys::thread::create::thread_start::ha3be9b31a8775143L4u
  27:     0x7fff8645b267 - _pthread_body
  28:     0x7fff8645b1e4 - _pthread_start

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions