Skip to content

broken MIR when transmuting integer to &'static () in const generic #72293

Closed

Description

Code

#![feature(const_generics)]

struct Const<const P: &'static ()>;

fn main() {
    const A: &'static () = unsafe {
        std::mem::transmute(10 as *const ())
    };

    let _ = Const::<{A}>;
}

Meta

rustc --version --verbose:

rustc 1.45.0-nightly (a74d1862d 2020-05-14)
binary: rustc
commit-hash: a74d1862d4d87a56244958416fd05976c58ca1a8
commit-date: 2020-05-14
host: x86_64-unknown-linux-gnu
release: 1.45.0-nightly
LLVM version: 9.0

Error output

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics, const_transmute)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

warning: 1 warning emitted

error: internal compiler error: broken MIR in DefId(0:6 ~ main[317d]::main[0]) (CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:4 ~ main[317d]::Const[0]::{{constructor}}[0]), UserSubsts { substs: [Const { ty: &'static (), val: Unevaluated(DefId(0:8 ~ main[317d]::main[0]::{{constant}}[0]), [], None) }], user_self_ty: None }) }, span: src/main.rs:10:13: 10:25, inferred_ty: Const<{transmute(0x000000000000000a): &()}> }): bad user type AscribeUserType(Const<{transmute(0x000000000000000a): &()}>, DefId(0:4 ~ main[317d]::Const[0]::{{constructor}}[0]) UserSubsts { substs: [Const { ty: &'static (), val: Unevaluated(DefId(0:8 ~ main[317d]::main[0]::{{constant}}[0]), [], None) }], user_self_ty: None }): NoSolution

error: internal compiler error: broken MIR in DefId(0:6 ~ main[317d]::main[0]) (_1 = Const::<{transmute(0x000000000000000a): &()}>): bad assignment (Const<{transmute(0x000000000000000a): &()}> = Const<{transmute(0x000000000000000a): &()}>): NoSolution
  --> src/main.rs:10:13
   |
10 |     let _ = Const::<{A}>;
   |             ^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:6 ~ main[317d]::main[0]) (_1 = Const::<{transmute(0x000000000000000a): &()}>): bad user type on rvalue (CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:4 ~ main[317d]::Const[0]::{{constructor}}[0]), UserSubsts { substs: [Const { ty: &'static (), val: Unevaluated(DefId(0:8 ~ main[317d]::main[0]::{{constant}}[0]), [], None) }], user_self_ty: None }) }, span: src/main.rs:10:13: 10:25, inferred_ty: Const<{transmute(0x000000000000000a): &()}> } = Const<{transmute(0x000000000000000a): &()}>): NoSolution
  --> src/main.rs:10:13
   |
10 |     let _ = Const::<{A}>;
   |             ^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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: rustc 1.45.0-nightly (a74d1862d 2020-05-14) running on x86_64-unknown-linux-gnu

Backtrace

stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
  12: std::panicking::begin_panic
  13: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
  14: core::ptr::drop_in_place
  15: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  16: core::ptr::drop_in_place
  17: rustc_interface::interface::run_compiler_in_existing_thread_pool
  18: scoped_tls::ScopedKey<T>::set
  19: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlA-const-genericsArea: const generics (parameters and arguments)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.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions