fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
16.3 KiB297 linesraw
1error[E0080]: it is undefined behavior to use this value
2  --> $DIR/ub-wide-ptr.rs:38:1
3   |
4LL | 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)
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: $SIZE, align: $ALIGN) {
9               HEX_DUMP
10           }
11
12error[E0080]: it is undefined behavior to use this value
13  --> $DIR/ub-wide-ptr.rs:40:1
14   |
15LL | 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
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: $SIZE, align: $ALIGN) {
20               HEX_DUMP
21           }
22
23error[E0080]: evaluation of constant value failed
24  --> $DIR/ub-wide-ptr.rs:43:1
25   |
26LL | const STR_LENGTH_PTR: &str = unsafe { mem::transmute((&42u8, &3)) };
27   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
28   |
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
31
32error[E0080]: evaluation of constant value failed
33  --> $DIR/ub-wide-ptr.rs:46:1
34   |
35LL | const MY_STR_LENGTH_PTR: &MyStr = unsafe { mem::transmute((&42u8, &3)) };
36   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
37   |
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
40
41error[E0080]: it is undefined behavior to use this value
42  --> $DIR/ub-wide-ptr.rs:48:1
43   |
44LL | 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
46   |
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: $SIZE, align: $ALIGN) {
49               HEX_DUMP
50           }
51
52error[E0080]: it is undefined behavior to use this value
53  --> $DIR/ub-wide-ptr.rs:52:1
54   |
55LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
56   | ^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered uninitialized memory, but expected a string
57   |
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: $SIZE, align: $ALIGN) {
60               HEX_DUMP
61           }
62
63error[E0080]: it is undefined behavior to use this value
64  --> $DIR/ub-wide-ptr.rs:55:1
65   |
66LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
67   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered uninitialized memory, but expected a string
68   |
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: $SIZE, align: $ALIGN) {
71               HEX_DUMP
72           }
73
74error[E0080]: evaluation of constant value failed
75  --> $DIR/ub-wide-ptr.rs:62:1
76   |
77LL | const SLICE_LENGTH_UNINIT: &[u8] = unsafe {
78   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
79
80error[E0080]: it is undefined behavior to use this value
81  --> $DIR/ub-wide-ptr.rs:69:1
82   |
83LL | 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)
85   |
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: $SIZE, align: $ALIGN) {
88               HEX_DUMP
89           }
90
91error[E0080]: it is undefined behavior to use this value
92  --> $DIR/ub-wide-ptr.rs:72:1
93   |
94LL | 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
96   |
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: $SIZE, align: $ALIGN) {
99               HEX_DUMP
100           }
101
102error[E0080]: evaluation of constant value failed
103  --> $DIR/ub-wide-ptr.rs:75:1
104   |
105LL | const SLICE_LENGTH_PTR: &[u8] = unsafe { mem::transmute((&42u8, &3)) };
106   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
107   |
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
110
111error[E0080]: it is undefined behavior to use this value
112  --> $DIR/ub-wide-ptr.rs:78:1
113   |
114LL | 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)
116   |
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: $SIZE, align: $ALIGN) {
119               HEX_DUMP
120           }
121
122error[E0080]: evaluation of constant value failed
123  --> $DIR/ub-wide-ptr.rs:81:1
124   |
125LL | const SLICE_LENGTH_PTR_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, &3)) };
126   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unable to turn pointer into integer
127   |
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
130
131error[E0080]: it is undefined behavior to use this value
132  --> $DIR/ub-wide-ptr.rs:85:1
133   |
134LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
135   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean
136   |
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: $SIZE, align: $ALIGN) {
139               HEX_DUMP
140           }
141
142note: erroneous constant encountered
143  --> $DIR/ub-wide-ptr.rs:85:40
144   |
145LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
146   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147
148error[E0080]: it is undefined behavior to use this value
149  --> $DIR/ub-wide-ptr.rs:92:1
150   |
151LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
152   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean
153   |
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: $SIZE, align: $ALIGN) {
156               HEX_DUMP
157           }
158
159note: erroneous constant encountered
160  --> $DIR/ub-wide-ptr.rs:92:42
161   |
162LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
163   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
164
165error[E0080]: it is undefined behavior to use this value
166  --> $DIR/ub-wide-ptr.rs:96:1
167   |
168LL | 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
170   |
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: $SIZE, align: $ALIGN) {
173               HEX_DUMP
174           }
175
176note: erroneous constant encountered
177  --> $DIR/ub-wide-ptr.rs:96:42
178   |
179LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
180   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
181
182error[E0080]: evaluation of constant value failed
183  --> $DIR/ub-wide-ptr.rs:104:1
184   |
185LL | const RAW_SLICE_LENGTH_UNINIT: *const [u8] = unsafe {
186   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
187
188error[E0080]: it is undefined behavior to use this value
189  --> $DIR/ub-wide-ptr.rs:113:1
190   |
191LL | 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
193   |
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: $SIZE, align: $ALIGN) {
196               HEX_DUMP
197           }
198
199error[E0080]: it is undefined behavior to use this value
200  --> $DIR/ub-wide-ptr.rs:117:1
201   |
202LL | 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
204   |
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: $SIZE, align: $ALIGN) {
207               HEX_DUMP
208           }
209
210error[E0080]: it is undefined behavior to use this value
211  --> $DIR/ub-wide-ptr.rs:121:1
212   |
213LL | 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
215   |
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: $SIZE, align: $ALIGN) {
218               HEX_DUMP
219           }
220
221error[E0080]: evaluation of constant value failed
222  --> $DIR/ub-wide-ptr.rs:124:57
223   |
224LL | 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
226
227error[E0080]: evaluation of constant value failed
228  --> $DIR/ub-wide-ptr.rs:127:57
229   |
230LL | 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
232
233error[E0080]: evaluation of constant value failed
234  --> $DIR/ub-wide-ptr.rs:130:56
235   |
236LL | 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
238
239error[E0080]: it is undefined behavior to use this value
240  --> $DIR/ub-wide-ptr.rs:133:1
241   |
242LL | 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
244   |
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: $SIZE, align: $ALIGN) {
247               HEX_DUMP
248           }
249
250error[E0080]: it is undefined behavior to use this value
251  --> $DIR/ub-wide-ptr.rs:138:1
252   |
253LL | 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
255   |
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: $SIZE, align: $ALIGN) {
258               HEX_DUMP
259           }
260
261error[E0080]: it is undefined behavior to use this value
262  --> $DIR/ub-wide-ptr.rs:143:1
263   |
264LL | 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
266   |
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: $SIZE, align: $ALIGN) {
269               HEX_DUMP
270           }
271
272error[E0080]: it is undefined behavior to use this value
273  --> $DIR/ub-wide-ptr.rs:145:1
274   |
275LL | 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
277   |
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: $SIZE, align: $ALIGN) {
280               HEX_DUMP
281           }
282
283error[E0080]: could not evaluate static initializer
284  --> $DIR/ub-wide-ptr.rs:151:5
285   |
286LL |     mem::transmute::<_, &dyn Trait>((&92u8, 0usize))
287   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ out-of-bounds pointer use: null pointer is a dangling pointer (it has no provenance)
288
289error[E0080]: could not evaluate static initializer
290  --> $DIR/ub-wide-ptr.rs:155:5
291   |
292LL |     mem::transmute::<_, &dyn Trait>((&92u8, &3u64))
293   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ using allocN as vtable pointer but it does not point to a vtable
294
295error: aborting due to 29 previous errors
296
297For more information about this error, try `rustc --explain E0080`.