rust-lang / rust-lang/rust-clippy

`transmutes_expressible_as_ptr_casts` does not detect reference-to-usize transmutes

Open
#8,622 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

Clippy by default lints against transmuting raw pointers to usize. However, it does not lint against transmuting references to usize. Both of these transmutes are highly questionable so it'd be good to lint them all.

Lint Name

transmutes_expressible_as_ptr_casts

Reproducer

I tried this code:

fn main() { unsafe {
    let _x: usize = std::mem::transmute(&0);
}}

I expected to see this happen: clippy should complain about the transmute.

Instead, this happened: clippy remains silent.

Version
Current playground

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the transmutes_expressible_as_ptr_casts lint and reproduce the reference-to-usize example from the issue. Done means the lint reports this transmute, while continuing to handle the raw-pointer case already described.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.