-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Help is not helpful for error #37338
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
Comments
It's not just unidiomatic, it actually does something completely different. |
Funny thing: casting *const f32 as i16 doesn't throw errors. I replace this error with another one which fit better. |
bors
added a commit
that referenced
this issue
Nov 17, 2016
Improve reference cast help message Fixes #37338.
GuillaumeGomez
added a commit
to GuillaumeGomez/rust
that referenced
this issue
Nov 23, 2016
…ndturner Provide hint when cast needs a dereference For a given code: ``` rust vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>(); ``` display: ``` nocode error: casting `&f64` as `i16` is invalid --> file3.rs:2:35 | 2 | vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>(); | - ^^^ | | | did you mean `*s`? ``` instead of: ``` nocode error: casting `&f64` as `i16` is invalid --> <anon>:2:30 | 2 | vec![0.0].iter().map(|s| s as i16).collect(); | ^^^^^^^^ | = help: cast through a raw pointer first ``` Fixes rust-lang#37338.
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
If you try to compile the code (play link):
You get the error
But casting through a raw pointer (
s as *const f64 as *const i16 as i16
) is not the idiomatic way IMO. Instead it should be fixed by simply dereferencing:The text was updated successfully, but these errors were encountered: