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

New issue

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

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

Already on GitHub? Sign in to your account

Closed
Centril opened this issue Jul 23, 2019 · 2 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Centril
Copy link
Contributor

Centril commented Jul 23, 2019

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

@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) labels Jul 23, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2019

It does make sense. Self::V2 is a function, is it not?

@Centril
Copy link
Contributor Author

Centril commented Jul 24, 2019

Oops! I forgot to apply the V2 in the test I was writing up.
When you apply it, you correctly get a cycle error.

Sorry for the noise!

@Centril Centril closed this as completed Jul 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants