Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of incorrect useless_conversion warnings when libc is involved #6466

Open
mahkoh opened this issue Dec 18, 2020 · 2 comments
Open

Lots of incorrect useless_conversion warnings when libc is involved #6466

mahkoh opened this issue Dec 18, 2020 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@mahkoh
Copy link

mahkoh commented Dec 18, 2020

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
    
@mahkoh mahkoh added the C-bug Category: Clippy is not doing the correct thing label Dec 18, 2020
@camsteffen camsteffen added E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 18, 2021
@camsteffen
Copy link
Contributor

I may be missing something, but why can't you just remove try_from like the lint suggests? In your example, you are converting cmsg_len which is size_t and size_t is an alias for usize. I don't see any #[cfg] attributes that would change those types for other platforms.

@kalcutter
Copy link

size_t and usize are semantically distinct types. There may be platforms where they differ now or in the future. Assuming they are the same type is a bug (clippy should have a lint for this).

See also: rust-lang/libc#1400

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-medium Call for participation: Medium difficulty level problem and requires some initial experience. I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants