@@ -9,29 +9,14 @@ LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
9
9
00 00 00 00 │ ....
10
10
}
11
11
12
- error: any use of this value will cause an error
12
+ error[E0080]: evaluation of constant value failed
13
13
--> $DIR/ub-nonnull.rs:19:30
14
14
|
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
32
17
33
18
error[E0080]: it is undefined behavior to use this value
34
- --> $DIR/ub-nonnull.rs:24 :1
19
+ --> $DIR/ub-nonnull.rs:23 :1
35
20
|
36
21
LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
37
22
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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) };
42
27
}
43
28
44
29
error[E0080]: it is undefined behavior to use this value
45
- --> $DIR/ub-nonnull.rs:26 :1
30
+ --> $DIR/ub-nonnull.rs:25 :1
46
31
|
47
32
LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
48
33
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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) };
53
38
}
54
39
55
40
error[E0080]: it is undefined behavior to use this value
56
- --> $DIR/ub-nonnull.rs:34 :1
41
+ --> $DIR/ub-nonnull.rs:33 :1
57
42
|
58
43
LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
59
44
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 };
64
49
}
65
50
66
51
error[E0080]: it is undefined behavior to use this value
67
- --> $DIR/ub-nonnull.rs:42 :1
52
+ --> $DIR/ub-nonnull.rs:41 :1
68
53
|
69
54
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
70
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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) };
75
60
}
76
61
77
62
error[E0080]: it is undefined behavior to use this value
78
- --> $DIR/ub-nonnull.rs:48 :1
63
+ --> $DIR/ub-nonnull.rs:47 :1
79
64
|
80
65
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
81
66
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30
0 commit comments