la10736 / rstest

Fixture-based test framework for Rust
Apache License 2.0
1.21k stars 43 forks source link

clippy::duplicated_attributes warning with rust 1.79.0-nightly #238

Closed asomers closed 7 months ago

asomers commented 7 months ago

With the latest Rust compiler, Clippy reports duplicated_attributes warnings from any rstest test function that has two Option arguments, if there is a test case that sets at least one of those arguments to None.

Reproduction Example

use rstest::rstest;

#[rstest]
#[case(None)]               // Doesn't warn
fn oneopt(#[case] _x: Option<u32>) {
    todo!()
}

#[rstest]
#[case(None, None)]         // warns
#[case(Some(1), None)]      // warns
#[case(None, Some(1.0))]    // warns
#[case(Some(1), Some(1.0))] // doesn't warn
fn twoopts(#[case] _x: Option<u32>, #[case] _y: Option<f64>) {
    todo!()
}

Compiler output:

warning: duplicated attribute
 --> mycrate/tests/da.rs:9:14
  |
9 | #[case(None, None)]
  |              ^^^^
  |
note: first defined here
 --> mycrate/tests/da.rs:9:8
  |
9 | #[case(None, None)]
  |        ^^^^
help: remove this attribute
 --> mycrate/tests/da.rs:9:14
  |
9 | #[case(None, None)]
  |              ^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
  = note: `#[warn(clippy::duplicated_attributes)]` on by default

warning: duplicated attribute
  --> mycrate/tests/da.rs:10:17
   |
10 | #[case(Some(1), None)]
   |                 ^^^^
   |
note: first defined here
  --> mycrate/tests/da.rs:9:8
   |
9  | #[case(None, None)]
   |        ^^^^
help: remove this attribute
  --> mycrate/tests/da.rs:10:17
   |
10 | #[case(Some(1), None)]
   |                 ^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

warning: duplicated attribute
  --> mycrate/tests/da.rs:11:8
   |
11 | #[case(None, Some(1.0))]
   |        ^^^^
   |
note: first defined here
  --> mycrate/tests/da.rs:9:8
   |
9  | #[case(None, None)]
   |        ^^^^
help: remove this attribute
  --> mycrate/tests/da.rs:11:8
   |
11 | #[case(None, Some(1.0))]
   |        ^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

warning: `mycrate` (test "da") generated 3 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.22s

Compiler version

> rustc --version --verbose
rustc 1.79.0-nightly (805813650 2024-03-31)
binary: rustc
commit-hash: 805813650248c1a2f6f271460d728d1bb852d2a7
commit-date: 2024-03-31
host: x86_64-unknown-freebsd
release: 1.79.0-nightly
LLVM version: 18.1.2
la10736 commented 7 months ago

It seems more a bug in clippy. As far I can understand seems they designed this check to handle duplication in #[allow(...)] attributes, but this approach doesn't work in general. I don't think I can find a way to work around this annoying thing.

la10736 commented 7 months ago

Seams an open problem in clippy https://github.com/rust-lang/rust-clippy/issues/12537

la10736 commented 7 months ago

Tested against clippy 0.1.79 (7f2fc33 2024-04-22) that didn't report any error.