-
Couldn't load subscription status.
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints
Description
If you try to compile the code (play link):
vec![0.0].iter().map(|s| s as i16).collect::<Vec<i16>>();You get the error
rustc 1.14.0-nightly (6e8f92f11 2016-10-07)
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
error: aborting due to previous 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:
vec![0.0].iter().map(|s| *s as i16).collect();GirkovArpa
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints