]> git.proxmox.com Git - rustc.git/blob - src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
New upstream version 1.53.0+dfsg1
[rustc.git] / src / test / ui / consts / const-eval / ub-nonnull.32bit.stderr
1 error[E0080]: it is undefined behavior to use this value
2 --> $DIR/ub-nonnull.rs:12:1
3 |
4 LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
5 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
6 |
7 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
8 = note: the raw bytes of the constant (size: 4, align: 4) {
9 00 00 00 00 │ ....
10 }
11
12 error: any use of this value will cause an error
13 --> $DIR/ub-nonnull.rs:19:30
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>
32
33 error[E0080]: it is undefined behavior to use this value
34 --> $DIR/ub-nonnull.rs:24:1
35 |
36 LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
37 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
38 |
39 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
40 = note: the raw bytes of the constant (size: 1, align: 1) {
41 00 │ .
42 }
43
44 error[E0080]: it is undefined behavior to use this value
45 --> $DIR/ub-nonnull.rs:26:1
46 |
47 LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
48 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
49 |
50 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
51 = note: the raw bytes of the constant (size: 4, align: 4) {
52 00 00 00 00 │ ....
53 }
54
55 error[E0080]: it is undefined behavior to use this value
56 --> $DIR/ub-nonnull.rs:34:1
57 |
58 LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
59 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes at .0, but expected initialized plain (non-pointer) bytes
60 |
61 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
62 = note: the raw bytes of the constant (size: 1, align: 1) {
63 __ │ ░
64 }
65
66 error[E0080]: it is undefined behavior to use this value
67 --> $DIR/ub-nonnull.rs:42:1
68 |
69 LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
70 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
71 |
72 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
73 = note: the raw bytes of the constant (size: 4, align: 4) {
74 2a 00 00 00 │ *...
75 }
76
77 error[E0080]: it is undefined behavior to use this value
78 --> $DIR/ub-nonnull.rs:48:1
79 |
80 LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
81 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30
82 |
83 = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
84 = note: the raw bytes of the constant (size: 4, align: 4) {
85 14 00 00 00 │ ....
86 }
87
88 error: aborting due to 7 previous errors
89
90 For more information about this error, try `rustc --explain E0080`.