1 error[E0080]: it is undefined behavior to use this value
2 --> $DIR/ub-ref-ptr.rs:13:1
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)
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) {
12 error[E0080]: it is undefined behavior to use this value
13 --> $DIR/ub-ref-ptr.rs:17:1
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)
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: 4, align: 4) {
23 error[E0080]: it is undefined behavior to use this value
24 --> $DIR/ub-ref-ptr.rs:21:1
26 LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
27 | ^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null reference
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: 4, align: 4) {
34 error[E0080]: it is undefined behavior to use this value
35 --> $DIR/ub-ref-ptr.rs:24:1
37 LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
38 | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a null box
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: 4, align: 4) {
45 error: any use of this value will cause an error
46 --> $DIR/ub-ref-ptr.rs:31:1
48 LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
49 | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
51 = note: `#[deny(const_err)]` on by default
52 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
53 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
54 = help: this code performed an operation that depends on the underlying bytes representing a pointer
55 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
57 error: any use of this value will cause an error
58 --> $DIR/ub-ref-ptr.rs:35:39
60 LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
61 | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
63 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
64 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
65 = help: this code performed an operation that depends on the underlying bytes representing a pointer
66 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
68 error: any use of this value will cause an error
69 --> $DIR/ub-ref-ptr.rs:35:38
71 LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
72 | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
74 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
75 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
77 error: any use of this value will cause an error
78 --> $DIR/ub-ref-ptr.rs:41:86
80 LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
81 | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
83 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
84 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
85 = help: this code performed an operation that depends on the underlying bytes representing a pointer
86 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
88 error: any use of this value will cause an error
89 --> $DIR/ub-ref-ptr.rs:41:85
91 LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
92 | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
94 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
95 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
97 error[E0080]: it is undefined behavior to use this value
98 --> $DIR/ub-ref-ptr.rs:47:1
100 LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
101 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (address 0x539 is unallocated)
103 = 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.
104 = note: the raw bytes of the constant (size: 4, align: 4) {
108 error[E0080]: it is undefined behavior to use this value
109 --> $DIR/ub-ref-ptr.rs:50:1
111 LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
112 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (address 0x539 is unallocated)
114 = 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.
115 = note: the raw bytes of the constant (size: 4, align: 4) {
119 error[E0080]: evaluation of constant value failed
120 --> $DIR/ub-ref-ptr.rs:53:41
122 LL | const UNINIT_PTR: *const i32 = unsafe { MaybeUninit { uninit: () }.init };
123 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
125 error[E0080]: it is undefined behavior to use this value
126 --> $DIR/ub-ref-ptr.rs:57:1
128 LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
129 | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a function pointer
131 = 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.
132 = note: the raw bytes of the constant (size: 4, align: 4) {
136 error[E0080]: evaluation of constant value failed
137 --> $DIR/ub-ref-ptr.rs:59:38
139 LL | const UNINIT_FN_PTR: fn() = unsafe { MaybeUninit { uninit: () }.init };
140 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
142 error[E0080]: it is undefined behavior to use this value
143 --> $DIR/ub-ref-ptr.rs:62:1
145 LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
146 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
148 = 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.
149 = note: the raw bytes of the constant (size: 4, align: 4) {
153 error[E0080]: it is undefined behavior to use this value
154 --> $DIR/ub-ref-ptr.rs:64:1
156 LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
157 | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered alloc41, but expected a function pointer
159 = 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.
160 = note: the raw bytes of the constant (size: 4, align: 4) {
164 error: aborting due to 16 previous errors
166 For more information about this error, try `rustc --explain E0080`.
167 Future incompatibility report: Future breakage diagnostic:
168 error: any use of this value will cause an error
169 --> $DIR/ub-ref-ptr.rs:31:1
171 LL | const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
172 | ^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
174 = note: `#[deny(const_err)]` on by default
175 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
176 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
177 = help: this code performed an operation that depends on the underlying bytes representing a pointer
178 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
180 Future breakage diagnostic:
181 error: any use of this value will cause an error
182 --> $DIR/ub-ref-ptr.rs:35:39
184 LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
185 | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
187 = note: `#[deny(const_err)]` on by default
188 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
189 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
190 = help: this code performed an operation that depends on the underlying bytes representing a pointer
191 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
193 Future breakage diagnostic:
194 error: any use of this value will cause an error
195 --> $DIR/ub-ref-ptr.rs:35:38
197 LL | const REF_AS_USIZE_SLICE: &[usize] = &[unsafe { mem::transmute(&0) }];
198 | ---------------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
200 = note: `#[deny(const_err)]` on by default
201 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
202 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
204 Future breakage diagnostic:
205 error: any use of this value will cause an error
206 --> $DIR/ub-ref-ptr.rs:41:86
208 LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
209 | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
211 = note: `#[deny(const_err)]` on by default
212 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
213 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
214 = help: this code performed an operation that depends on the underlying bytes representing a pointer
215 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
217 Future breakage diagnostic:
218 error: any use of this value will cause an error
219 --> $DIR/ub-ref-ptr.rs:41:85
221 LL | const REF_AS_USIZE_BOX_SLICE: Box<[usize]> = unsafe { mem::transmute::<&[usize], _>(&[mem::transmute(&0)]) };
222 | ------------------------------------------ ^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
224 = note: `#[deny(const_err)]` on by default
225 = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
226 = note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>