1error[E0080]: it is undefined behavior to use this value
2  --> $DIR/ub-nonnull.rs:12:1
3   |
4LL | 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
12error[E0080]: evaluation of constant value failed
13  --> $DIR/ub-nonnull.rs:19:30
14   |
15LL |     let out_of_bounds_ptr = &ptr[255];
16   |                              ^^^^^^^^ dereferencing pointer failed: alloc11 has size 1, so pointer to 256 bytes starting at offset 0 is out-of-bounds
17
18error[E0080]: it is undefined behavior to use this value
19  --> $DIR/ub-nonnull.rs:23:1
20   |
21LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
22   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
23   |
24   = 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.
25   = note: the raw bytes of the constant (size: 1, align: 1) {
26               00                                              │ .
27           }
28
29error[E0080]: it is undefined behavior to use this value
30  --> $DIR/ub-nonnull.rs:25:1
31   |
32LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
33   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
34   |
35   = 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.
36   = note: the raw bytes of the constant (size: 4, align: 4) {
37               00 00 00 00                                     │ ....
38           }
39
40error[E0080]: it is undefined behavior to use this value
41  --> $DIR/ub-nonnull.rs:33:1
42   |
43LL | const UNINIT: NonZeroU8 = unsafe { MaybeUninit { uninit: () }.init };
44   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .0: encountered uninitialized bytes, but expected initialized plain (non-pointer) bytes
45   |
46   = 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.
47   = note: the raw bytes of the constant (size: 1, align: 1) {
48               __                                              │ ░
49           }
50
51error[E0080]: it is undefined behavior to use this value
52  --> $DIR/ub-nonnull.rs:41:1
53   |
54LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
55   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
56   |
57   = 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.
58   = note: the raw bytes of the constant (size: 4, align: 4) {
59               2a 00 00 00                                     │ *...
60           }
61
62error[E0080]: it is undefined behavior to use this value
63  --> $DIR/ub-nonnull.rs:47:1
64   |
65LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
66   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30
67   |
68   = 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.
69   = note: the raw bytes of the constant (size: 4, align: 4) {
70               14 00 00 00                                     │ ....
71           }
72
73error: aborting due to 7 previous errors
74
75For more information about this error, try `rustc --explain E0080`.
76