Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uniformative error message when casting a thin raw pointer to a fat one #31511

Closed
SimonSapin opened this issue Feb 9, 2016 · 0 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@SimonSapin
Copy link
Contributor

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

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 15, 2016
bors added a commit that referenced this issue Mar 14, 2016
Give a more accurate error on thin-to-fat ptr cast

Fixes #31511
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

2 participants