Skip to content

ICE when passing () to a function generic over Copy #42148

Closed
@archshift

Description

@archshift
#![feature(core_intrinsics)]
extern crate core;
use core::intrinsics;

fn write_reg<T: Copy>(reg: u32, val: T) {
    unsafe { intrinsics::volatile_store(reg as *mut T, val); }
}

fn main() {
    write_reg(0x10000000, ());
}

I was met with an internal compiler error:
error: internal compiler error: unexpected panic

I expected some kind of user-comprehensible error, instead.

Meta

Rust version: rustc 1.19.0-nightly (01951a61a 2017-05-20)

Associated Rust Playground: https://is.gd/ZHy4Av

Backtrace:

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /checkout/src/librustc_trans/intrinsic.rs:248
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:355
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:365
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:549
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:511
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:495
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:471
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:69
   9: core::panicking::panic_bounds_check
             at /checkout/src/libcore/panicking.rs:56
  10: rustc_trans::intrinsic::trans_intrinsic_call
  11: rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_block
  12: rustc_trans::mir::trans_mir
  13: rustc_trans::trans_item::TransItem::define
  14: rustc_trans::base::trans_crate
  15: rustc_driver::driver::phase_4_translate_to_llvm
  16: rustc_driver::driver::compile_input::{{closure}}
  17: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  18: rustc_driver::driver::phase_3_run_analysis_passes
  19: rustc_driver::driver::compile_input
  20: rustc_driver::run_compiler

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions