]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-eval/ub-ref-ptr.64bit.stderr
Reuse the ctfe error emitting logic for the future incompat lint
[rust.git] / src / test / ui / consts / const-eval / ub-ref-ptr.64bit.stderr
1 error[E0080]: it is undefined behavior to use this value
2   --> $DIR/ub-ref-ptr.rs:14:1
3    |
4 LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
5    | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 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: 8, align: 8) {
9                ╾───────alloc3────────╼                         │ ╾──────╼
10            }
11
12 error[E0080]: it is undefined behavior to use this value
13   --> $DIR/ub-ref-ptr.rs:18:1
14    |
15 LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
16    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1)
17    |
18    = 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.
19    = note: the raw bytes of the constant (size: 8, align: 8) {
20                ╾───────alloc7────────╼                         │ ╾──────╼
21            }
22
23 error[E0080]: it is undefined behavior to use this value
24   --> $DIR/ub-ref-ptr.rs:22:1
25    |
26 LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
27    | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
28    |
29    = 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.
30    = note: the raw bytes of the constant (size: 8, align: 8) {
31                00 00 00 00 00 00 00 00                         │ ........
32            }
33
34 error[E0080]: it is undefined behavior to use this value
35   --> $DIR/ub-ref-ptr.rs:25:1
36    |
37 LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
38    | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box
39    |
40    = 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.
41    = note: the raw bytes of the constant (size: 8, align: 8) {
42                00 00 00 00 00 00 00 00                         │ ........
43            }
44
45 error[E0080]: evaluation of constant value failed
46   --> $DIR/ub-ref-ptr.rs:32:1
47    |
48 LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
49    | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
50    |
51    = help: this code performed an operation that depends on the underlying bytes representing a pointer
52    = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
53
54 error[E0080]: evaluation of constant value failed
55   --> $DIR/ub-ref-ptr.rs:35:39
56    |
57 LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
58    |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
59    |
60    = help: this code performed an operation that depends on the underlying bytes representing a pointer
61    = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
62
63 note: erroneous constant used
64   --> $DIR/ub-ref-ptr.rs:35:38
65    |
66 LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
67    |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
68
69 error[E0080]: evaluation of constant value failed
70   --> $DIR/ub-ref-ptr.rs:38:86
71    |
72 LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
73    |                                                                                      ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
74    |
75    = help: this code performed an operation that depends on the underlying bytes representing a pointer
76    = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
77
78 note: erroneous constant used
79   --> $DIR/ub-ref-ptr.rs:38:85
80    |
81 LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
82    |                                                                                     ^^^^^^^^^^^^^^^^^^^^^
83
84 error[E0080]: it is undefined behavior to use this value
85   --> $DIR/ub-ref-ptr.rs:41:1
86    |
87 LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
88    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (address 0x539 is unallocated)
89    |
90    = 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.
91    = note: the raw bytes of the constant (size: 8, align: 8) {
92                39 05 00 00 00 00 00 00                         │ 9.......
93            }
94
95 error[E0080]: it is undefined behavior to use this value
96   --> $DIR/ub-ref-ptr.rs:44:1
97    |
98 LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
99    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (address 0x539 is unallocated)
100    |
101    = 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.
102    = note: the raw bytes of the constant (size: 8, align: 8) {
103                39 05 00 00 00 00 00 00                         │ 9.......
104            }
105
106 error[E0080]: evaluation of constant value failed
107   --> $DIR/ub-ref-ptr.rs:47:41
108    |
109 LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
110    |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
111
112 error[E0080]: it is undefined behavior to use this value
113   --> $DIR/ub-ref-ptr.rs:51:1
114    |
115 LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
116    | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
117    |
118    = 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.
119    = note: the raw bytes of the constant (size: 8, align: 8) {
120                00 00 00 00 00 00 00 00                         │ ........
121            }
122
123 error[E0080]: evaluation of constant value failed
124   --> $DIR/ub-ref-ptr.rs:53:38
125    |
126 LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
127    |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
128
129 error[E0080]: it is undefined behavior to use this value
130   --> $DIR/ub-ref-ptr.rs:56:1
131    |
132 LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
133    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
134    |
135    = 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.
136    = note: the raw bytes of the constant (size: 8, align: 8) {
137                0d 00 00 00 00 00 00 00                         │ ........
138            }
139
140 error[E0080]: it is undefined behavior to use this value
141   --> $DIR/ub-ref-ptr.rs:58:1
142    |
143 LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
144    | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer
145    |
146    = 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.
147    = note: the raw bytes of the constant (size: 8, align: 8) {
148                ╾───────alloc41───────╼                         │ ╾──────╼
149            }
150
151 error: accessing memory with alignment 1, but alignment 4 is required
152   --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
153    |
154    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
155    = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616>
156 note: inside `std::ptr::read::<u32>`
157   --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
158 note: inside `ptr::const_ptr::<impl *const u32>::read`
159   --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
160 note: inside `UNALIGNED_READ`
161   --> $DIR/ub-ref-ptr.rs:65:5
162    |
163 LL |     ptr.read();
164    |     ^^^^^^^^^^
165    = note: `#[deny(invalid_alignment)]` on by default
166
167 error: aborting due to 15 previous errors
168
169 For more information about this error, try `rustc --explain E0080`.
170 Future incompatibility report: Future breakage diagnostic:
171 error: accessing memory with alignment 1, but alignment 4 is required
172   --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
173    |
174    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
175    = note: for more information, see issue #68585 <https://github.com/rust-lang/rust/issues/104616>
176 note: inside `std::ptr::read::<u32>`
177   --> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
178 note: inside `ptr::const_ptr::<impl *const u32>::read`
179   --> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
180 note: inside `UNALIGNED_READ`
181   --> $DIR/ub-ref-ptr.rs:65:5
182    |
183 LL |     ptr.read();
184    |     ^^^^^^^^^^
185    = note: `#[deny(invalid_alignment)]` on by default
186