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

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

Closed
asomers opened this issue Apr 5, 2024 · 3 comments
Closed

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

asomers opened this issue Apr 5, 2024 · 3 comments

Comments

@asomers
Copy link

asomers commented Apr 5, 2024

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
asomers added a commit to asomers/bfffs that referenced this issue Apr 5, 2024
The latest nightly toolchains report this lint for rstest's generated
code.

la10736/rstest#238
@la10736
Copy link
Owner

la10736 commented Apr 6, 2024

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
Copy link
Owner

la10736 commented Apr 9, 2024

Seams an open problem in clippy rust-lang/rust-clippy#12537

@la10736
Copy link
Owner

la10736 commented Apr 23, 2024

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

@la10736 la10736 closed this as completed Apr 23, 2024
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

2 participants