Skip to content

Commit 20dee47

Browse files
committed
Add regression test for integral pointers in zst str slice fat pointers
1 parent df1ed0c commit 20dee47

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
2+
3+
fn main() {}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/int_ptr_for_zst_slices.rs:1:28
3+
|
4+
LL | const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected str, found slice
6+
|
7+
= note: expected type `&'static str`
8+
found type `&[str]`
9+
10+
error[E0277]: the size for values of type `str` cannot be known at compilation time
11+
--> $DIR/int_ptr_for_zst_slices.rs:1:75
12+
|
13+
LL | const FOO: &str = unsafe { &*(1_usize as *const [u8; 0] as *const [u8] as *const [str]) };
14+
| ^^^^^^^^^^^^ doesn't have a size known at compile-time
15+
|
16+
= help: the trait `std::marker::Sized` is not implemented for `str`
17+
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
18+
= note: slice and array elements must have `Sized` type
19+
20+
error: aborting due to 2 previous errors
21+
22+
Some errors occurred: E0277, E0308.
23+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)