Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Area: implicit and explicit `expr as Type` coercionsArea: Messages for errors, warnings, and lintsDiagnostics: Confusing error or lint that should be reworked.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.Relevant to the compiler team, which will review and decide on the PR/issue.