Skip to content

enum discriminants have problems with const_eval and truncation #9837

Closed
@jld

Description

@jld
static S: i16 = 0x12345678;
enum E { V = S }
fn main() { assert_eq!(S as u64, V as u64); }

Result:

task '<unnamed>' failed at 'assertion failed: `(left == right) && (right == left)` (left: `22136u64`, right: `305419896u64`)', testcase.rs:3`

Currently blocking #9613, because 32-bit std::int::min_value is 0xffffffff7fffffff (if you use all the bits of the const_eval result and not just the low 32) and so the discriminant is auto-sized to u64, meaning that 0x7fffffff does not match any of its variants.

I'm thinking that check_enum_variants needs to do whatever const_eval would do if the expression had an as u64 around it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions