Skip to content

Dangling raw pointers in constants will ICE in codegen #55353

Closed
@oli-obk

Description

@oli-obk

cc @RalfJung

#![feature(const_let)]

const FOO: *const u32 = {
    let x = 42;
    &x
};

fn main() {
    let x = FOO;
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
warning: unused variable: `x`
  --> src/main.rs:10:9
   |
10 |     let x = FOO;
   |         ^ help: consider using `_x` instead
   |
   = note: #[warn(unused_variables)] on by default

error: internal compiler error: librustc_mir/monomorphize/collector.rs:1174: alloc id without corresponding allocation: 3

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:600:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to previous error


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.31.0-nightly (f99911a4a 2018-10-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)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