diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs')
-rw-r--r-- | src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs b/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs deleted file mode 100644 index 83e74a6e6..000000000 --- a/src/test/ui/enum-discriminant/arbitrary_enum_discriminant.rs +++ /dev/null @@ -1,43 +0,0 @@ -// run-pass -#![feature(test)] - -extern crate test; - -use test::black_box; - -#[allow(dead_code)] -#[repr(u8)] -enum Enum { - Unit = 3, - Tuple(u16) = 2, - Struct { - a: u8, - b: u16, - } = 1, -} - -impl Enum { - const unsafe fn tag(&self) -> u8 { - *(self as *const Self as *const u8) - } -} - -fn main() { - const UNIT: Enum = Enum::Unit; - const TUPLE: Enum = Enum::Tuple(5); - const STRUCT: Enum = Enum::Struct{a: 7, b: 11}; - - // Ensure discriminants are correct during runtime execution - assert_eq!(3, unsafe { black_box(UNIT).tag() }); - assert_eq!(2, unsafe { black_box(TUPLE).tag() }); - assert_eq!(1, unsafe { black_box(STRUCT).tag() }); - - // Ensure discriminants are correct during CTFE - const UNIT_TAG: u8 = unsafe { UNIT.tag() }; - const TUPLE_TAG: u8 = unsafe { TUPLE.tag() }; - const STRUCT_TAG: u8 = unsafe { STRUCT.tag() }; - - assert_eq!(3, UNIT_TAG); - assert_eq!(2, TUPLE_TAG); - assert_eq!(1, STRUCT_TAG); -} |