]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/ub-nonnull.stderr
Update const_forget.rs
[rust.git] / src / test / ui / consts / const-eval / ub-nonnull.stderr
1 error[E0080]: it is undefined behavior to use this value
2   --> $DIR/ub-nonnull.rs:11: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
9 error: any use of this value will cause an error
10   --> $DIR/ub-nonnull.rs:18:29
11    |
12 LL | / const OUT_OF_BOUNDS_PTR: NonNull<u8> = { unsafe {
13 LL | |     let ptr: &[u8; 256] = mem::transmute(&0u8); // &0 gets promoted so it does not dangle
14 LL | |     // Use address-of-element for pointer arithmetic. This could wrap around to NULL!
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 allocation 8 which has size 1
17 LL | |     mem::transmute(out_of_bounds_ptr)
18 LL | | } };
19    | |____-
20    |
21 note: the lint level is defined here
22   --> $DIR/ub-nonnull.rs:14:8
23    |
24 LL | #[deny(const_err)] // this triggers a `const_err` so validation does not even happen
25    |        ^^^^^^^^^
26
27 error[E0080]: it is undefined behavior to use this value
28   --> $DIR/ub-nonnull.rs:22:1
29    |
30 LL | const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
31    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
32    |
33    = 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.
34
35 error[E0080]: it is undefined behavior to use this value
36   --> $DIR/ub-nonnull.rs:24:1
37    |
38 LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
39    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0, but expected something greater or equal to 1
40    |
41    = 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.
42
43 error[E0080]: it is undefined behavior to use this value
44   --> $DIR/ub-nonnull.rs:32:1
45    |
46 LL | const UNINIT: NonZeroU8 = unsafe { Transmute { uninit: () }.out };
47    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered uninitialized bytes, but expected something greater or equal to 1
48    |
49    = 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.
50
51 error[E0080]: it is undefined behavior to use this value
52   --> $DIR/ub-nonnull.rs:40:1
53    |
54 LL | 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
59 error[E0080]: it is undefined behavior to use this value
60   --> $DIR/ub-nonnull.rs:46:1
61    |
62 LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
63    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30
64    |
65    = 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.
66
67 error: aborting due to 7 previous errors
68
69 For more information about this error, try `rustc --explain E0080`.