Skip to content

ICE when casting negative discriminant enum values to anything less than bit width #70114

Closed
@afinch7

Description

@afinch7

Compiling this code on playground:

enum Nums {
    NegOne = -1,
}

fn main() {
    let kind = Nums::NegOne;
    let _v = kind as i32;
}

results in ICE. Casting to anything smaller than usize/isize(u32, u16, i16, u8, i8, etc) also results in ICE. Casting to anything same size or larger(u128, i128, u64, i64, etc) works fine. Positive discriminant values also work fine.
Version of rustc: rustc 1.42.0 (b8cedc004 2020-03-09) running on x86_64-unknown-linux-gnu(on rust playground)
Compiler flags listed as used: -C codegen-units=1 -C debuginfo=2 --crate-type bin

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions