@@ -9,29 +9,14 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
99 00 00 00 00 │ ....
1010 }
1111
12- error: any use of this value will cause an error
12+ error[E0080]: evaluation of constant value failed
1313 --> $DIR/ub-nonnull.rs:19:30
1414 |
15- LL | / const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
16- LL | | let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
17- LL | | // Use address-of-element for pointer arithmetic. This could wrap around to null!
18- LL | | let out_of_bounds_ptr = &ptr[255];
19- | | ^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc10 which has size 1
20- LL | |
21- LL | | mem::transmute(out_of_bounds_ptr)
22- LL | | } };
23- | |____-
24- |
25- note: the lint level is defined here
26- --> $DIR/ub-nonnull.rs:15:8
27- |
28- LL | #[deny(const_err)] // this triggers a `const_err` so validation does not even happen
29- | ^^^^^^^^^
30- = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31- = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
15+ LL | let out_of_bounds_ptr = &ptr[255];
16+ | ^^^^^^^^ memory access failed: pointer must be in-bounds at offset 256, but is outside bounds of alloc10 which has size 1
3217
3318error[E0080]: it is undefined behavior to use this value
34- --> $DIR/ub-nonnull.rs:24 :1
19+ --> $DIR/ub-nonnull.rs:23 :1
3520 |
3621LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
3722 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
@@ -42,7 +27,7 @@ LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
4227 }
4328
4429error[E0080]: it is undefined behavior to use this value
45- --> $DIR/ub-nonnull.rs:26 :1
30+ --> $DIR/ub-nonnull.rs:25 :1
4631 |
4732LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
4833 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
@@ -53,7 +38,7 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
5338 }
5439
5540error[E0080]: it is undefined behavior to use this value
56- --> $DIR/ub-nonnull.rs:34 :1
41+ --> $DIR/ub-nonnull.rs:33 :1
5742 |
5843LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
5944 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
@@ -64,7 +49,7 @@ LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
6449 }
6550
6651error[E0080]: it is undefined behavior to use this value
67- --> $DIR/ub-nonnull.rs:42 :1
52+ --> $DIR/ub-nonnull.rs:41 :1
6853 |
6954LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
7055 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
@@ -75,7 +60,7 @@ LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
7560 }
7661
7762error[E0080]: it is undefined behavior to use this value
78- --> $DIR/ub-nonnull.rs:48 :1
63+ --> $DIR/ub-nonnull.rs:47 :1
7964 |
8065LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
8166 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30
0 commit comments