Skip to content

#[derive(Arbitrary)] causes a clippy warning #227

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

Closed
KeenS opened this issue Feb 16, 2021 · 2 comments
Closed

#[derive(Arbitrary)] causes a clippy warning #227

KeenS opened this issue Feb 16, 2021 · 2 comments

Comments

@KeenS
Copy link

KeenS commented Feb 16, 2021

Running clippy against this code generates following warning

use proptest_derive::Arbitrary;

#[derive(Debug, Arbitrary)]
struct User {
    id: i32,
}

fn main() {}
$ cargo clippy -- -Wclippy::all
    Checking proptest-clippy v0.1.0 (/home/shun/Rust/proptest-clippy)
warning: passing a unit value to a function
 --> src/main.rs:5:5
  |
5 |     id: i32,
  |     ^^
  |
  = note: `-W clippy::unit-arg` implied by `-W clippy::all`
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
help: move the expression in front of the call and replace it with the unit literal `()`
  |
5 |     {
6 |         Arbitrary;
7 |         id
8 |     }: i32,
  |

warning: 1 warning emitted

    Finished dev [unoptimized + debuginfo] target(s) in 0.04s

This is too noisy. Is there any chance to address this issue in the library side?

Note that adding #[allow(clippy::unit_arg)] to the type doesn't solve this problem because the warning is from the generated code. One (cumbersome) way to silence this warning in user side is wrapping the definition with mod and allow all lints inside the mod:

mod types {
    #![allow(clippy::all)]

    use super::*;
    #[derive(Debug, Arbitrary)]
    pub(super) struct User {
        pub(super) id: i32,
    }
}

Though the warning can be silenced by the method above, it would be grateful if the derive macro generates that code.

@ghost
Copy link

ghost commented Feb 18, 2021

A Clippy bug has already been logged for this. rust-lang/rust-clippy#6594

Personally, I wouldn't add work arounds for Clippy bugs.

@KeenS
Copy link
Author

KeenS commented Feb 22, 2021

Then I'll watch that issue. Thank you.

@KeenS KeenS closed this as completed Feb 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant