Closed
Description
This is fine:
fn cast_thin_to_thin(x: *const ()) {
x as *const u8;
}
This does not compile, but the error message is not particularly helpful:
fn cast_thin_to_fat(x: *const ()) {
x as *const [u8];
}
a.rs:8:5: 8:21 error: casting `*const ()` as `*const [u8]` is invalid
a.rs:8 x as *const [u8];
^~~~~~~~~~~~~~~~
error: aborting due to previous error
Invalid how? The error message should mention thin vs fat pointers or statically-sized vs dynamically-sized types, and maybe link to https://doc.rust-lang.org/book/unsized-types.html
(To make this a bit less artificial, this came up in FFI code casting *mut c_void
to a struct containing an unboxed FnMut
closure. The fix was to box the closure to make that struct statically-sized.)
CC @julienw