Skip to content

Help is not helpful for error #37338

Closed
Closed
@est31

Description

@est31

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions