Skip to content

Commit 3414c03

Browse files
committed
test forbidden slices on all two usizesizes
1 parent f4fff04 commit 3414c03

File tree

3 files changed

+309
-28
lines changed

3 files changed

+309
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
error[E0080]: could not evaluate static initializer
2+
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
3+
|
4+
LL | &*ptr::slice_from_raw_parts(data, len)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| dereferencing pointer failed: null pointer is not a valid pointer
8+
| inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
9+
|
10+
::: $DIR/forbidden_slices.rs:17:34
11+
|
12+
LL | pub static S0: &[u32] = unsafe { from_raw_parts(ptr::null(), 0) };
13+
| ------------------------------ inside `S0` at $DIR/forbidden_slices.rs:17:34
14+
15+
error[E0080]: could not evaluate static initializer
16+
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
17+
|
18+
LL | &*ptr::slice_from_raw_parts(data, len)
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
| |
21+
| dereferencing pointer failed: null pointer is not a valid pointer
22+
| inside `std::slice::from_raw_parts::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
23+
|
24+
::: $DIR/forbidden_slices.rs:18:33
25+
|
26+
LL | pub static S1: &[()] = unsafe { from_raw_parts(ptr::null(), 0) };
27+
| ------------------------------ inside `S1` at $DIR/forbidden_slices.rs:18:33
28+
29+
error[E0080]: could not evaluate static initializer
30+
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
31+
|
32+
LL | &*ptr::slice_from_raw_parts(data, len)
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
| |
35+
| dereferencing pointer failed: alloc26 has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
36+
| inside `std::slice::from_raw_parts::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
37+
|
38+
::: $DIR/forbidden_slices.rs:21:34
39+
|
40+
LL | pub static S2: &[u32] = unsafe { from_raw_parts(&D0, 2) };
41+
| ---------------------- inside `S2` at $DIR/forbidden_slices.rs:21:34
42+
43+
error[E0080]: it is undefined behavior to use this value
44+
--> $DIR/forbidden_slices.rs:24:1
45+
|
46+
LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) };
47+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>[0]: encountered uninitialized bytes
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+
= note: the raw bytes of the constant (size: 8, align: 4) {
51+
╾─alloc42─╼ 01 00 00 00 │ ╾──╼....
52+
}
53+
54+
error[E0080]: it is undefined behavior to use this value
55+
--> $DIR/forbidden_slices.rs:26:1
56+
|
57+
LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, size_of::<&u32>()) };
58+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>: encountered a pointer, but expected plain (non-pointer) bytes
59+
|
60+
= 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.
61+
= note: the raw bytes of the constant (size: 8, align: 4) {
62+
╾─alloc55─╼ 04 00 00 00 │ ╾──╼....
63+
}
64+
65+
error[E0080]: it is undefined behavior to use this value
66+
--> $DIR/forbidden_slices.rs:28:1
67+
|
68+
LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) };
69+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed at .<deref>[0]: encountered 0x11, but expected a boolean
70+
|
71+
= 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.
72+
= note: the raw bytes of the constant (size: 8, align: 4) {
73+
╾─alloc65─╼ 04 00 00 00 │ ╾──╼....
74+
}
75+
76+
error[E0080]: it is undefined behavior to use this value
77+
--> $DIR/forbidden_slices.rs:31:1
78+
|
79+
LL | / pub static S7: &[u16] = unsafe {
80+
LL | |
81+
LL | | let ptr = (&D2 as *const Struct as *const u16).byte_add(1);
82+
LL | |
83+
LL | | from_raw_parts(ptr, 4)
84+
LL | | };
85+
| |__^ type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1)
86+
|
87+
= 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.
88+
= note: the raw bytes of the constant (size: 8, align: 4) {
89+
╾─a79+0x1─╼ 04 00 00 00 │ ╾──╼....
90+
}
91+
92+
error[E0080]: could not evaluate static initializer
93+
--> $SRC_DIR/core/src/slice/raw.rs:LL:COL
94+
|
95+
LL | &*ptr::slice_from_raw_parts(data, len)
96+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97+
| |
98+
| dereferencing pointer failed: alloc96 has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
99+
| inside `std::slice::from_raw_parts::<u64>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
100+
|
101+
::: $DIR/forbidden_slices.rs:42:5
102+
|
103+
LL | from_raw_parts(ptr, 1)
104+
| ---------------------- inside `S8` at $DIR/forbidden_slices.rs:42:5
105+
106+
error[E0080]: could not evaluate static initializer
107+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
108+
|
109+
LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
110+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111+
| |
112+
| out-of-bounds offset_from: null pointer is not a valid pointer
113+
| inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
114+
|
115+
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
116+
|
117+
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
118+
| ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
119+
|
120+
::: $DIR/forbidden_slices.rs:45:34
121+
|
122+
LL | pub static R0: &[u32] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
123+
| ---------------------------------------- inside `R0` at $DIR/forbidden_slices.rs:45:34
124+
125+
error[E0080]: could not evaluate static initializer
126+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
127+
|
128+
LL | assert!(0 < pointee_size && pointee_size <= isize::MAX as usize);
129+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
130+
| |
131+
| the evaluated program panicked at 'assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize', $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
132+
| inside `ptr::const_ptr::<impl *const ()>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
133+
|
134+
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
135+
|
136+
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
137+
| ------------------------------ inside `from_ptr_range::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
138+
|
139+
::: $DIR/forbidden_slices.rs:46:33
140+
|
141+
LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
142+
| ---------------------------------------- inside `R1` at $DIR/forbidden_slices.rs:46:33
143+
|
144+
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
145+
146+
error[E0080]: could not evaluate static initializer
147+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
148+
|
149+
LL | unsafe { intrinsics::offset(self, count) }
150+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151+
| |
152+
| pointer arithmetic failed: alloc154 has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
153+
| inside `ptr::const_ptr::<impl *const u32>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
154+
...
155+
LL | unsafe { self.offset(count as isize) }
156+
| --------------------------- inside `ptr::const_ptr::<impl *const u32>::add` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
157+
|
158+
::: $DIR/forbidden_slices.rs:49:25
159+
|
160+
LL | from_ptr_range(ptr..ptr.add(2))
161+
| ---------- inside `R2` at $DIR/forbidden_slices.rs:49:25
162+
163+
error[E0080]: it is undefined behavior to use this value
164+
--> $DIR/forbidden_slices.rs:51:1
165+
|
166+
LL | / pub static R4: &[u8] = unsafe {
167+
LL | |
168+
LL | | let ptr = (&D1) as *const MaybeUninit<&u32> as *const u8;
169+
LL | | from_ptr_range(ptr..ptr.add(1))
170+
LL | | };
171+
| |__^ type validation failed at .<deref>[0]: encountered uninitialized bytes
172+
|
173+
= 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.
174+
= note: the raw bytes of the constant (size: 8, align: 4) {
175+
╾alloc159─╼ 01 00 00 00 │ ╾──╼....
176+
}
177+
178+
error[E0080]: it is undefined behavior to use this value
179+
--> $DIR/forbidden_slices.rs:56:1
180+
|
181+
LL | / pub static R5: &[u8] = unsafe {
182+
LL | |
183+
LL | | let ptr = &D3 as *const &u32;
184+
LL | | from_ptr_range(ptr.cast()..ptr.add(1).cast())
185+
LL | | };
186+
| |__^ type validation failed at .<deref>: encountered a pointer, but expected plain (non-pointer) bytes
187+
|
188+
= 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.
189+
= note: the raw bytes of the constant (size: 8, align: 4) {
190+
╾alloc175─╼ 04 00 00 00 │ ╾──╼....
191+
}
192+
193+
error[E0080]: it is undefined behavior to use this value
194+
--> $DIR/forbidden_slices.rs:61:1
195+
|
196+
LL | / pub static R6: &[bool] = unsafe {
197+
LL | |
198+
LL | | let ptr = &D0 as *const u32 as *const bool;
199+
LL | | from_ptr_range(ptr..ptr.add(4))
200+
LL | | };
201+
| |__^ type validation failed at .<deref>[0]: encountered 0x11, but expected a boolean
202+
|
203+
= 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.
204+
= note: the raw bytes of the constant (size: 8, align: 4) {
205+
╾alloc191─╼ 04 00 00 00 │ ╾──╼....
206+
}
207+
208+
error[E0080]: it is undefined behavior to use this value
209+
--> $DIR/forbidden_slices.rs:66:1
210+
|
211+
LL | / pub static R7: &[u16] = unsafe {
212+
LL | |
213+
LL | | let ptr = (&D2 as *const Struct as *const u16).byte_add(1);
214+
LL | | from_ptr_range(ptr..ptr.add(4))
215+
LL | | };
216+
| |__^ type validation failed: encountered an unaligned reference (required 2 byte alignment but found 1)
217+
|
218+
= 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.
219+
= note: the raw bytes of the constant (size: 8, align: 4) {
220+
╾a209+0x1─╼ 04 00 00 00 │ ╾──╼....
221+
}
222+
223+
error[E0080]: could not evaluate static initializer
224+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
225+
|
226+
LL | unsafe { intrinsics::offset(self, count) }
227+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
228+
| |
229+
| pointer arithmetic failed: alloc230 has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
230+
| inside `ptr::const_ptr::<impl *const u64>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
231+
...
232+
LL | unsafe { self.offset(count as isize) }
233+
| --------------------------- inside `ptr::const_ptr::<impl *const u64>::add` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
234+
|
235+
::: $DIR/forbidden_slices.rs:73:25
236+
|
237+
LL | from_ptr_range(ptr..ptr.add(1))
238+
| ---------- inside `R8` at $DIR/forbidden_slices.rs:73:25
239+
240+
error[E0080]: could not evaluate static initializer
241+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
242+
|
243+
LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
244+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
245+
| |
246+
| ptr_offset_from_unsigned cannot compute offset of pointers into different allocations.
247+
| inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
248+
|
249+
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
250+
|
251+
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
252+
| ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
253+
|
254+
::: $DIR/forbidden_slices.rs:78:34
255+
|
256+
LL | pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
257+
| ----------------------------------------------- inside `R9` at $DIR/forbidden_slices.rs:78:34
258+
259+
error[E0080]: could not evaluate static initializer
260+
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
261+
|
262+
LL | unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
263+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
264+
| |
265+
| ptr_offset_from_unsigned cannot compute offset of pointers into different allocations.
266+
| inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
267+
|
268+
::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
269+
|
270+
LL | unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
271+
| ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
272+
|
273+
::: $DIR/forbidden_slices.rs:79:35
274+
|
275+
LL | pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
276+
| ------------------------ inside `R10` at $DIR/forbidden_slices.rs:79:35
277+
278+
error: aborting due to 18 previous errors
279+
280+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)