summaryrefslogtreecommitdiffstats
path: root/src/test/ui/consts/const-eval/ub-nonnull.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-nonnull.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-nonnull.rs')
-rw-r--r--src/test/ui/consts/const-eval/ub-nonnull.rs57
1 files changed, 0 insertions, 57 deletions
diff --git a/src/test/ui/consts/const-eval/ub-nonnull.rs b/src/test/ui/consts/const-eval/ub-nonnull.rs
deleted file mode 100644
index 490925822..000000000
--- a/src/test/ui/consts/const-eval/ub-nonnull.rs
+++ /dev/null
@@ -1,57 +0,0 @@
-// stderr-per-bitwidth
-#![feature(rustc_attrs, ptr_metadata)]
-#![allow(invalid_value)] // make sure we cannot allow away the errors tested here
-
-use std::mem;
-use std::ptr::NonNull;
-use std::num::{NonZeroU8, NonZeroUsize};
-
-const NON_NULL: NonNull<u8> = unsafe { mem::transmute(1usize) };
-const NON_NULL_PTR: NonNull<u8> = unsafe { mem::transmute(&1) };
-
-const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
-//~^ ERROR it is undefined behavior to use this value
-
-const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
- let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
- // Use address-of-element for pointer arithmetic. This could wrap around to null!
- let out_of_bounds_ptr = &ptr[255]; //~ ERROR evaluation of constant value failed
- mem::transmute(out_of_bounds_ptr)
-} };
-
-const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
-//~^ ERROR it is undefined behavior to use this value
-const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
-//~^ ERROR it is undefined behavior to use this value
-
-#[repr(C)]
-union MaybeUninit<T: Copy> {
- uninit: (),
- init: T,
-}
-const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
-//~^ ERROR evaluation of constant value failed
-//~| uninitialized
-
-// Also test other uses of rustc_layout_scalar_valid_range_start
-
-#[rustc_layout_scalar_valid_range_start(10)]
-#[rustc_layout_scalar_valid_range_end(30)]
-struct RestrictedRange1(u32);
-const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
-//~^ ERROR it is undefined behavior to use this value
-
-#[rustc_layout_scalar_valid_range_start(30)]
-#[rustc_layout_scalar_valid_range_end(10)]
-struct RestrictedRange2(u32);
-const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
-//~^ ERROR it is undefined behavior to use this value
-
-const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
-//~^ ERROR it is undefined behavior to use this value
- let x: &dyn Send = &42;
- let meta = std::ptr::metadata(x);
- mem::transmute((0_usize, meta))
-};
-
-fn main() {}