Skip to content

ICE when compiling an 'extern "C"' trait method #21238

@skade

Description

@skade
Contributor

This piece of rust code crashes rustc:

pub trait Test {
  #[no_mangle]
  extern "C" fn something(&self) -> i32;
}

#[derive(Copy)]
pub struct Foo {
  field: i32
}

impl Test for Foo {
  extern "C" fn something(&self) -> i32 {
    self.field
  }
}

This, however, does not:

pub trait Test {
  #[no_mangle]
  extern "C" fn something(&self) -> i32;
}

#[derive(Copy)]
pub struct Foo {
  field: i32
}

Backtrace:

$ RUST_BACKTRACE=1 rustc -v --crate-type dylib rustmodule.rs
error: internal compiler error: unexpected panic
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 'assertion failed: f.abi == Rust || f.abi == RustCall', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/base.rs:2445

stack backtrace:
   1:     0x7f2513d4f000 - sys::backtrace::write::h7e8ba1fc274cc36epRt
   2:     0x7f2513d709e0 - failure::on_fail::h823798930ebe140a64z
   3:     0x7f2513cdf7b0 - rt::unwind::begin_unwind_inner::ha4a8df6010104da6ZJz
   4:     0x7f2512ca5c70 - rt::unwind::begin_unwind::h18244988485934784102
   5:     0x7f2512dc4fb0 - trans::base::register_fn::h5c1883ad97c86009tGu
   6:     0x7f2512dc6c60 - trans::base::register_method::h17503a3e81ec29861kv
   7:     0x7f2512cde480 - trans::base::get_item_val::hd9784892acf07040s3u
   8:     0x7f2512cdc1f0 - trans::base::trans_item::h1e3916042030bab0Uyu
   9:     0x7f2512dc6f20 - trans::base::trans_crate::h035c45eac4628807Buv
  10:     0x7f25142aeb60 - driver::phase_4_translate_to_llvm::h1b361a483c335af2YMa
  11:     0x7f251428ed70 - driver::compile_input::h8ec974b2bd4afe59Aba
  12:     0x7f25143504d0 - run_compiler::h0e495a7c10e57aaae5b
  13:     0x7f251434ec40 - thunk::F.Invoke<A, R>::invoke::h12226774702741163622
  14:     0x7f251434dba0 - rt::unwind::try::try_fn::h67848939709837360
  15:     0x7f2513dd7b90 - rust_try_inner
  16:     0x7f2513dd7b80 - rust_try
  17:     0x7f251434de50 - thunk::F.Invoke<A, R>::invoke::h15720675569063176780
  18:     0x7f2513d5e680 - sys::thread::thread_start::h2ac456e96ea03cedcJw
  19:     0x7f250e16adc0 - start_thread
  20:                0x0 - <unknown>

Version:

rustc 1.0.0-nightly (8903c21d6 2015-01-15 22:42:58 +0000)

I'm not sure whether this is intended to be legal, though :).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemI-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

        Participants

        @skade@kmcallister

        Issue actions

          ICE when compiling an 'extern "C"' trait method · Issue #21238 · rust-lang/rust