Skip to content

False positive unit-arg when deriving proptest::arbitrary::Arbitrary #6594

Closed
@turion

Description

@turion

Lint name: unit-arg

I tried this code:

use proptest_derive::Arbitrary;

#[derive(Debug, Arbitrary)]
struct Foo(i64);

fn main() {
    println!("Hello, world!");
}

I expected to see this happen: clippy passes

Instead, this happened:

error: passing a unit value to a function
 --> src/main.rs:4:12
  |
4 | struct Foo(i64);
  |            ^^^
  |
  = note: `-D clippy::unit-arg` implied by `-D warnings`
  = 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 `()`
  |
4 | struct Foo({
5 |     Arbitrary;
6 |     i64
7 | });
  |

I've only seen this happen with https://github.com/AltSysrq/proptest/.

A more complicated example passes:

use proptest_derive::Arbitrary;

#[derive(Debug, Arbitrary)]
struct Foo<T>(T);

fn main() {
    println!("Hello, world!");
}

Possibly this is because some macro expanded code triggered the issue? cargo expand yields:

#![feature(prelude_import)]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std;
use proptest_derive::Arbitrary;
struct Foo(i64);
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Foo {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match *self {
            Foo(ref __self_0_0) => {
                let mut debug_trait_builder = f.debug_tuple("Foo");
                let _ = debug_trait_builder.field(&&(*__self_0_0));
                debug_trait_builder.finish()
            }
        }
    }
}
#[allow(non_upper_case_globals)]
const _IMPL_ARBITRARY_FOR_Foo: () = {
    extern crate proptest as _proptest;
    impl _proptest::arbitrary::Arbitrary for Foo {
        type Parameters = <i64 as _proptest::arbitrary::Arbitrary>::Parameters;
        type Strategy = _proptest::strategy::Map<
            (<i64 as _proptest::arbitrary::Arbitrary>::Strategy,),
            fn((i64,)) -> Self,
        >;
        fn arbitrary_with(_top: Self::Parameters) -> Self::Strategy {
            {
                let param_0 = _top;
                _proptest::strategy::Strategy::prop_map(
                    (_proptest::arbitrary::any_with::<i64>(param_0),),
                    |(tmp_0,)| Foo { 0: tmp_0 },
                )
            }
        }
    }
};
fn main() {
    {
        ::std::io::_print(::core::fmt::Arguments::new_v1(
            &["Hello, world!\n"],
            &match () {
                () => [],
            },
        ));
    };
}

Possibly the line const _IMPL_ARBITRARY_FOR_Foo: () = { triggers the false positive?

Meta

  • cargo clippy -V: clippy 0.1.51 (e38fb30 2021-01-14)
  • rustc -Vv:
    rustc 1.51.0-nightly (e38fb306b 2021-01-14)
    binary: rustc
    commit-hash: e38fb306b7f5e65cca34df2dab1f0db15e1defb4
    commit-date: 2021-01-14
    host: x86_64-unknown-linux-gnu
    release: 1.51.0-nightly
    LLVM version: 11.0
    

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions