Skip to content

useless_transmute being raised when it's doing multiple casts #1545

Closed
@wfraser

Description

@wfraser

Here's a code sample:

warning: transmute from a reference to a pointer
  --> src/main.rs:35:29
   |
35 |         let fd = libc::open(mem::transmute(b"/dev/null\0"), libc::O_RDONLY);
   |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: #[warn(useless_transmute)] on by default
help: try
   |         let fd = libc::open(b"/dev/null\0" as *const [u8; 10] as *const i8, libc::O_RDONLY);
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#useless_transmute

That seems kind of silly. It's not useless; it's doing two casts at once (reference to pointer, and then pointer to different pointer) and saving quite a bit of typing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesL-unnecessaryLint: Warn about unnecessary codeT-middleType: Probably requires verifiying typesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions