Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
afinch7 opened this issue Mar 18, 2020 · 2 comments · Fixed by #70126
Closed

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

afinch7 opened this issue Mar 18, 2020 · 2 comments · Fixed by #70126
Assignees
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@afinch7
Copy link

afinch7 commented Mar 18, 2020

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

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 18, 2020
@Centril Centril added regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Mar 18, 2020
@pnkfelix
Copy link
Member

godbolt indicates that this was injected in Rust 1.40

@Centril Centril added P-high High priority and removed I-nominated labels Mar 18, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 18, 2020
@RalfJung
Copy link
Member

Thanks for the report!

Please always include the ICE message. This time, it seems to be

Unsigned value 0xffffffffffffffff does not fit in 32 bits

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants