-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.Diagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.