Skip to content

arbitrary_enum_discriminant: needs raw ptr -> usize cast + "a raw memory access tried to access part of a pointer value as raw bytes" #62915

Closed
@Centril

Description

@Centril

With:

#![feature(arbitrary_enum_discriminant)]

#[repr(u8)]
enum Beta {
    V1 = 41,
    V2() = Self::V2 as u8 + 1,
}

something seemingly strange is going on:

error[E0658]: casting pointers to integers in constants is unstable
 --> src/lib.rs:6:12
  |
6 |     V2() = Self::V2 as u8 + 1,
  |            ^^^^^^^^^^^^^^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/51910
  = help: add `#![feature(const_raw_ptr_to_usize_cast)]` to the crate attributes to enable

error[E0080]: evaluation of constant value failed
 --> src/lib.rs:6:12
  |
6 |     V2() = Self::V2 as u8 + 1,
  |            ^^^^^^^^^^^^^^ a raw memory access tried to access part of a pointer value as raw bytes

error: aborting due to 2 previous errors

I haven't looked at the MIR, but it's strange that a raw pointer -> usize cast is going on here?

cc #60553
cc @oli-obk @eddyb

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions