Skip to content

Panic when trying to create two static slices of an array #21891

Closed
@LeoTestard

Description

@LeoTestard

The following code raises an panic in librustc_trans:

static foo_1: [uint; 3] = [1, 2, 3];

static slice_1: &'static [uint] = &foo_1;
static slice_2: &'static [uint] = &foo_1;

fn main() {} 
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: cx.const_globals().borrow_mut().insert(llptr as int, llconst).is_none()', /home/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_trans/trans/consts.rs:244

The error happens on this assertion.

Just taking references to the array (&'static [uint; 3]) works, so I think this is specific to slices.
I don't see why this code should be invalid, but even if it is, it should be handled better.

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