1 error[E0080]: it is undefined behavior to use this value
2 --> $DIR/ub-wide-ptr.rs:36:1
4 LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
5 | ^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
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: 16, align: 8) {
9 ╾───────allocN────────╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........
12 error[E0080]: it is undefined behavior to use this value
13 --> $DIR/ub-wide-ptr.rs:38:1
15 LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },);
16 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object
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: 16, align: 8) {
20 ╾───────allocN───────╼ ff ff ff ff ff ff ff ff │ ╾──────╼........
23 error[E0080]: evaluation of constant value failed
24 --> $DIR/ub-wide-ptr.rs:41:1
26 LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
27 | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
29 = help: this code performed an operation that depends on the underlying bytes representing a pointer
30 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
32 error[E0080]: evaluation of constant value failed
33 --> $DIR/ub-wide-ptr.rs:44:1
35 LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
36 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
38 = help: this code performed an operation that depends on the underlying bytes representing a pointer
39 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
41 error[E0080]: it is undefined behavior to use this value
42 --> $DIR/ub-wide-ptr.rs:46:1
44 LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
45 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
47 = 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.
48 = note: the raw bytes of the constant (size: 16, align: 8) {
49 ╾───────allocN───────╼ ff ff ff ff ff ff ff ff │ ╾──────╼........
52 error[E0080]: it is undefined behavior to use this value
53 --> $DIR/ub-wide-ptr.rs:50:1
55 LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
56 | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized data in `str`
58 = 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.
59 = note: the raw bytes of the constant (size: 16, align: 8) {
60 ╾───────allocN───────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........
63 error[E0080]: it is undefined behavior to use this value
64 --> $DIR/ub-wide-ptr.rs:53:1
66 LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
67 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized data in `str`
69 = 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.
70 = note: the raw bytes of the constant (size: 16, align: 8) {
71 ╾───────allocN───────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........
74 error[E0080]: evaluation of constant value failed
75 --> $DIR/ub-wide-ptr.rs:60:1
77 LL | const SLICE_LENGTH_UNINIT: &[u8] = unsafe {
78 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
80 error[E0080]: it is undefined behavior to use this value
81 --> $DIR/ub-wide-ptr.rs:67:1
83 LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
84 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
86 = 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.
87 = note: the raw bytes of the constant (size: 16, align: 8) {
88 ╾───────allocN───────╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........
91 error[E0080]: it is undefined behavior to use this value
92 --> $DIR/ub-wide-ptr.rs:70:1
94 LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) };
95 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
97 = 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.
98 = note: the raw bytes of the constant (size: 16, align: 8) {
99 ╾───────allocN───────╼ ff ff ff ff ff ff ff 7f │ ╾──────╼........
102 error[E0080]: evaluation of constant value failed
103 --> $DIR/ub-wide-ptr.rs:73:1
105 LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
106 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
108 = help: this code performed an operation that depends on the underlying bytes representing a pointer
109 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
111 error[E0080]: it is undefined behavior to use this value
112 --> $DIR/ub-wide-ptr.rs:76:1
114 LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
115 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation)
117 = 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.
118 = note: the raw bytes of the constant (size: 16, align: 8) {
119 ╾───────allocN───────╼ e7 03 00 00 00 00 00 00 │ ╾──────╼........
122 error[E0080]: evaluation of constant value failed
123 --> $DIR/ub-wide-ptr.rs:79:1
125 LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
126 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into raw bytes
128 = help: this code performed an operation that depends on the underlying bytes representing a pointer
129 = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
131 error[E0080]: it is undefined behavior to use this value
132 --> $DIR/ub-wide-ptr.rs:83:1
134 LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
135 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean
137 = 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.
138 = note: the raw bytes of the constant (size: 8, align: 8) {
139 ╾───────allocN───────╼ │ ╾──────╼
142 note: erroneous constant used
143 --> $DIR/ub-wide-ptr.rs:83:40
145 LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
146 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
148 error[E0080]: it is undefined behavior to use this value
149 --> $DIR/ub-wide-ptr.rs:90:1
151 LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
152 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean
154 = 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.
155 = note: the raw bytes of the constant (size: 8, align: 8) {
156 ╾──────allocN───────╼ │ ╾──────╼
159 note: erroneous constant used
160 --> $DIR/ub-wide-ptr.rs:90:42
162 LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
163 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
165 error[E0080]: it is undefined behavior to use this value
166 --> $DIR/ub-wide-ptr.rs:94:1
168 LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
169 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean
171 = 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.
172 = note: the raw bytes of the constant (size: 8, align: 8) {
173 ╾──────allocN───────╼ │ ╾──────╼
176 note: erroneous constant used
177 --> $DIR/ub-wide-ptr.rs:94:42
179 LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
180 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
182 error[E0080]: evaluation of constant value failed
183 --> $DIR/ub-wide-ptr.rs:102:1
185 LL | const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
186 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
188 error[E0080]: it is undefined behavior to use this value
189 --> $DIR/ub-wide-ptr.rs:111:1
191 LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
192 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
194 = 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.
195 = note: the raw bytes of the constant (size: 16, align: 8) {
196 ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼
199 error[E0080]: it is undefined behavior to use this value
200 --> $DIR/ub-wide-ptr.rs:115:1
202 LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
203 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
205 = 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.
206 = note: the raw bytes of the constant (size: 16, align: 8) {
207 ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼
210 error[E0080]: it is undefined behavior to use this value
211 --> $DIR/ub-wide-ptr.rs:119:1
213 LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
214 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
216 = 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.
217 = note: the raw bytes of the constant (size: 16, align: 8) {
218 ╾──────allocN───────╼ 04 00 00 00 00 00 00 00 │ ╾──────╼........
221 error[E0080]: evaluation of constant value failed
222 --> $DIR/ub-wide-ptr.rs:122:57
224 LL | const TRAIT_OBJ_UNALIGNED_VTABLE: &dyn Trait = unsafe { mem::transmute((&92u8, &[0u8; 128])) };
225 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
227 error[E0080]: evaluation of constant value failed
228 --> $DIR/ub-wide-ptr.rs:125:57
230 LL | const TRAIT_OBJ_BAD_DROP_FN_NULL: &dyn Trait = unsafe { mem::transmute((&92u8, &[0usize; 8])) };
231 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
233 error[E0080]: evaluation of constant value failed
234 --> $DIR/ub-wide-ptr.rs:128:56
236 LL | const TRAIT_OBJ_BAD_DROP_FN_INT: &dyn Trait = unsafe { mem::transmute((&92u8, &[1usize; 8])) };
237 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
239 error[E0080]: it is undefined behavior to use this value
240 --> $DIR/ub-wide-ptr.rs:131:1
242 LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
243 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .0: encountered allocN, but expected a vtable pointer
245 = 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.
246 = note: the raw bytes of the constant (size: 16, align: 8) {
247 ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼
250 error[E0080]: it is undefined behavior to use this value
251 --> $DIR/ub-wide-ptr.rs:136:1
253 LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
254 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
256 = 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.
257 = note: the raw bytes of the constant (size: 16, align: 8) {
258 ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼
261 error[E0080]: it is undefined behavior to use this value
262 --> $DIR/ub-wide-ptr.rs:141:1
264 LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
265 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered null pointer, but expected a vtable pointer
267 = 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.
268 = note: the raw bytes of the constant (size: 16, align: 8) {
269 ╾──────allocN───────╼ 00 00 00 00 00 00 00 00 │ ╾──────╼........
272 error[E0080]: it is undefined behavior to use this value
273 --> $DIR/ub-wide-ptr.rs:143:1
275 LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
276 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered allocN, but expected a vtable pointer
278 = 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.
279 = note: the raw bytes of the constant (size: 16, align: 8) {
280 ╾──────allocN───────╼ ╾──────allocN───────╼ │ ╾──────╼╾──────╼
283 error[E0080]: could not evaluate static initializer
284 --> $DIR/ub-wide-ptr.rs:149:5
286 LL | mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
287 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
289 error[E0080]: could not evaluate static initializer
290 --> $DIR/ub-wide-ptr.rs:153:5
292 LL | mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
293 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
295 error: aborting due to 29 previous errors
297 For more information about this error, try `rustc --explain E0080`.