rust-lang / rust-lang/rust-clippy

Lots of incorrect useless_conversion warnings when libc is involved

Open
#6,466 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I tried this code:

    let cmsg_len = match usize::try_from(hdr.cmsg_len) {
        Ok(l) => l,
        _ => return einval(),
    };

I expected to see this happen: Nothing, as cmsg_len is u32 on many platforms.

Instead, this happened:

warning: useless conversion to the same type: `usize`
  --> uapi/src/socket/cmsg.rs:71:26
   |
71 |     let cmsg_len = match usize::try_from(hdr.cmsg_len) {
   |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider removing `usize::try_from()`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
Meta
  • cargo clippy -V: clippy 0.0.212 (7eac88a 2020-11-16)
  • rustc -Vv:
     rustc 1.48.0 (7eac88abb 2020-11-16)
     binary: rustc
     commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
     commit-date: 2020-11-16
     host: x86_64-unknown-linux-gnu
     release: 1.48.0
     LLVM version: 11.0
    

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 with the reported example in uapi/src/socket/cmsg.rs at line 71 and reproduce the useless_conversion warning with the listed Rust and Clippy versions. Trace how the lint handles libc-dependent types across platforms; done means the warning is no longer emitted when the conversion is necessary while remaining for genuinely useless conversions.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.