Rollup merge of #90910 - RalfJung:const-discriminant-empty-enum, r=petrochenkov
fix getting the discriminant of a zero-variant enum Fixes https://github.com/rust-lang/rust/issues/89765
This commit is contained in:
commit
6d9c3a1b97
2 changed files with 10 additions and 1 deletions
|
|
@ -25,6 +25,13 @@ enum SingleVariant {
|
|||
|
||||
const TEST_V: Discriminant<SingleVariant> = discriminant(&SingleVariant::V);
|
||||
|
||||
pub const TEST_VOID: () = {
|
||||
// This is UB, but CTFE does not check validity so it does not detect this.
|
||||
// This is a regression test for https://github.com/rust-lang/rust/issues/89765.
|
||||
unsafe { std::mem::discriminant(&*(&() as *const () as *const Void)); };
|
||||
};
|
||||
|
||||
|
||||
fn main() {
|
||||
assert_eq!(TEST_A, TEST_A_OTHER);
|
||||
assert_eq!(TEST_A, discriminant(black_box(&Test::A(17))));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue