Given the following code: playground
fn main() {
maybe_sized_t::<()>();
}
fn maybe_sized_t<T: ?Sized>() {
let _ptr = 0 as *mut T;
}
The current output is:
error[E0606]: casting `usize` as `*mut T` is invalid
--> src/main.rs:6:16
|
6 | let _ptr = 0 as *mut T;
| ^^^^^^^^^^^
For more information about this error, try `rustc --explain E0606`.
error: could not compile `playground` due to previous error
error[E0606]: casting `usize` as `*mut T` is invalid
--> src/main.rs:6:16
|
6 | let _ptr = 0 as *mut T;
| ^^^^^^^^^^^
For more information about this error, try `rustc --explain E0606`.
error: could not compile `playground` due to previous error
note: `*mut T` is a fat pointer, and can therefore not be built from a `usize`
Casting a usize to a regular pointer is possible, so it's a bit confusing at first that this doesn't work for fat pointers, especially if it's not obvious that *mut T is a fat pointer here.
Given the following code: playground
The current output is:
Casting a
usizeto a regular pointer is possible, so it's a bit confusing at first that this doesn't work for fat pointers, especially if it's not obvious that*mut Tis a fat pointer here.