summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/const-eval/ub-enum.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/test/ui/consts/const-eval/ub-enum.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-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/consts/const-eval/ub-enum.rs')
-rw-r--r--src/test/ui/consts/const-eval/ub-enum.rs99
1 files changed, 0 insertions, 99 deletions
diff --git a/src/test/ui/consts/const-eval/ub-enum.rs b/src/test/ui/consts/const-eval/ub-enum.rs
deleted file mode 100644
index 6935be2f9..000000000
--- a/src/test/ui/consts/const-eval/ub-enum.rs
+++ /dev/null
@@ -1,99 +0,0 @@
-// stderr-per-bitwidth
-#![feature(never_type)]
-#![allow(invalid_value)]
-
-use std::mem;
-
-#[repr(transparent)]
-#[derive(Copy, Clone)]
-struct Wrap<T>(T);
-
-#[derive(Copy, Clone)]
-enum Never {}
-
-// # simple enum with discriminant 0
-
-#[repr(usize)]
-#[derive(Copy, Clone)]
-enum Enum {
- A = 0,
-}
-
-const GOOD_ENUM: Enum = unsafe { mem::transmute(0usize) };
-
-const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
-//~^ ERROR is undefined behavior
-
-const BAD_ENUM_PTR: Enum = unsafe { mem::transmute(&1) };
-//~^ ERROR evaluation of constant value failed
-
-const BAD_ENUM_WRAPPED: Wrap<Enum> = unsafe { mem::transmute(&1) };
-//~^ ERROR evaluation of constant value failed
-
-// # simple enum with discriminant 2
-
-// (Potentially) invalid enum discriminant
-#[repr(usize)]
-#[derive(Copy, Clone)]
-enum Enum2 {
- A = 2,
-}
-
-const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
-//~^ ERROR is undefined behavior
-const BAD_ENUM2_PTR: Enum2 = unsafe { mem::transmute(&0) };
-//~^ ERROR evaluation of constant value failed
-// something wrapping the enum so that we test layout first, not enum
-const BAD_ENUM2_WRAPPED: Wrap<Enum2> = unsafe { mem::transmute(&0) };
-//~^ ERROR evaluation of constant value failed
-
-// Undef enum discriminant.
-#[repr(C)]
-union MaybeUninit<T: Copy> {
- uninit: (),
- init: T,
-}
-const BAD_ENUM2_UNDEF : Enum2 = unsafe { MaybeUninit { uninit: () }.init };
-//~^ ERROR evaluation of constant value failed
-//~| uninitialized
-
-// Pointer value in an enum with a niche that is not just 0.
-const BAD_ENUM2_OPTION_PTR: Option<Enum2> = unsafe { mem::transmute(&0) };
-//~^ ERROR evaluation of constant value failed
-
-// # valid discriminant for uninhabited variant
-
-// An enum with 3 variants of which some are uninhabited -- so the uninhabited variants *do*
-// have a discriminant.
-enum UninhDiscriminant {
- A,
- B(!),
- C,
- D(Never),
-}
-
-const GOOD_INHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(0u8) }; // variant A
-const GOOD_INHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(2u8) }; // variant C
-
-const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
-//~^ ERROR is undefined behavior
-const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
-//~^ ERROR is undefined behavior
-
-// # other
-
-// Invalid enum field content (mostly to test printing of paths for enum tuple
-// variants and tuples).
-// Need to create something which does not clash with enum layout optimizations.
-const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
-//~^ ERROR is undefined behavior
-
-// All variants are uninhabited but also have data.
-// Use `0` as constant to make behavior endianness-independent.
-const BAD_UNINHABITED_WITH_DATA1: Result<(i32, Never), (i32, !)> = unsafe { mem::transmute(0u64) };
-//~^ ERROR evaluation of constant value failed
-const BAD_UNINHABITED_WITH_DATA2: Result<(i32, !), (i32, Never)> = unsafe { mem::transmute(0u64) };
-//~^ ERROR evaluation of constant value failed
-
-fn main() {
-}