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

duplicated_attributes false positive: cfg expressions #12537

Closed
dtolnay opened this issue Mar 23, 2024 · 25 comments · Fixed by #12646
Closed

duplicated_attributes false positive: cfg expressions #12537

dtolnay opened this issue Mar 23, 2024 · 25 comments · Fixed by #12646
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 23, 2024

Lint Name

duplicated_attributes

Reproducer

#[cfg(any(
    all(
        target_os = "linux",
        any(
            target_arch = "aarch64",
            target_arch = "arm",
            target_arch = "hexagon",
            target_arch = "powerpc",
            target_arch = "powerpc64",
            target_arch = "s390x",
            target_arch = "riscv64",
            target_arch = "riscv32"
        )
    ),
    all(
        target_os = "android",
        any(target_arch = "aarch64", target_arch = "arm")
    ),
))]
pub type c_char = u8;
$ cargo clippy
warning: duplicated attribute
  --> src/main.rs:17:13
   |
17 |         any(target_arch = "aarch64", target_arch = "arm")
   |             ^^^^^^^^^^^^^^^^^^^^^^^
   |
note: first defined here
  --> src/main.rs:5:13
   |
5  |             target_arch = "aarch64",
   |             ^^^^^^^^^^^^^^^^^^^^^^^
help: remove this attribute
  --> src/main.rs:17:13
   |
17 |         any(target_arch = "aarch64", target_arch = "arm")
   |             ^^^^^^^^^^^^^^^^^^^^^^^
   = 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
  --> src/main.rs:17:38
   |
17 |         any(target_arch = "aarch64", target_arch = "arm")
   |                                      ^^^^^^^^^^^^^^^^^^^
   |
note: first defined here
  --> src/main.rs:6:13
   |
6  |             target_arch = "arm",
   |             ^^^^^^^^^^^^^^^^^^^
help: remove this attribute
  --> src/main.rs:17:38
   |
17 |         any(target_arch = "aarch64", target_arch = "arm")
   |                                      ^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

Clippy just says "remove this attribute" but doing so would violate the intended meaning of the program.

The case shown as an example of the intended purpose of this lint in https://rust-lang.github.io/rust-clippy/master/index.html#/duplicated_attributes (#[allow(dead_code)] #[allow(dead_code)]) seems like a quite different thing than this one.

Version

rustc 1.79.0-nightly (85e449a32 2024-03-22)
binary: rustc
commit-hash: 85e449a3237e82c9ade8936a82bd4fc64cfe1057
commit-date: 2024-03-22
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Additional Labels

No response

@dtolnay dtolnay added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 23, 2024
@dtolnay
Copy link
Member Author

dtolnay commented Mar 23, 2024

@GuillaumeGomez @blyxyas (the lint is new from #12378)

dtolnay added a commit to dtolnay/cxx that referenced this issue Mar 23, 2024
rust-lang/rust-clippy#12537

    warning: duplicated attribute
      --> src/c_char.rs:28:17
       |
    28 |             any(target_arch = "aarch64", target_arch = "arm")
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:16:17
       |
    16 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:28:17
       |
    28 |             any(target_arch = "aarch64", target_arch = "arm")
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       = 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
      --> src/c_char.rs:28:42
       |
    28 |             any(target_arch = "aarch64", target_arch = "arm")
       |                                          ^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:17:17
       |
    17 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:28:42
       |
    28 |             any(target_arch = "aarch64", target_arch = "arm")
       |                                          ^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:34:17
       |
    34 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:16:17
       |
    16 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:34:17
       |
    34 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:35:17
       |
    35 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:17:17
       |
    17 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:35:17
       |
    35 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:36:17
       |
    36 |                 target_arch = "powerpc",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:19:17
       |
    19 |                 target_arch = "powerpc",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:36:17
       |
    36 |                 target_arch = "powerpc",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:37:17
       |
    37 |                 target_arch = "powerpc64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:20:17
       |
    20 |                 target_arch = "powerpc64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:37:17
       |
    37 |                 target_arch = "powerpc64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:38:17
       |
    38 |                 target_arch = "riscv64"
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:22:17
       |
    22 |                 target_arch = "riscv64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:38:17
       |
    38 |                 target_arch = "riscv64"
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:43:17
       |
    43 |             any(target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc")
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:16:17
       |
    16 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:43:17
       |
    43 |             any(target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc")
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:43:42
       |
    43 |             any(target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc")
       |                                          ^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:17:17
       |
    17 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:43:42
       |
    43 |             any(target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc")
       |                                          ^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:43:63
       |
    43 |             any(target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc")
       |                                                               ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:19:17
       |
    19 |                 target_arch = "powerpc",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:43:63
       |
    43 |             any(target_arch = "aarch64", target_arch = "arm", target_arch = "powerpc")
       |                                                               ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:49:17
       |
    49 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:16:17
       |
    16 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:49:17
       |
    49 |                 target_arch = "aarch64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:50:17
       |
    50 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:17:17
       |
    17 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:50:17
       |
    50 |                 target_arch = "arm",
       |                 ^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:51:17
       |
    51 |                 target_arch = "powerpc64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:20:17
       |
    20 |                 target_arch = "powerpc64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:51:17
       |
    51 |                 target_arch = "powerpc64",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:52:17
       |
    52 |                 target_arch = "powerpc"
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:19:17
       |
    19 |                 target_arch = "powerpc",
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:52:17
       |
    52 |                 target_arch = "powerpc"
       |                 ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: duplicated attribute
      --> src/c_char.rs:55:36
       |
    55 |         all(target_os = "fuchsia", target_arch = "aarch64")
       |                                    ^^^^^^^^^^^^^^^^^^^^^^^
       |
    note: first defined here
      --> src/c_char.rs:45:36
       |
    45 |         all(target_os = "openbsd", target_arch = "aarch64"),
       |                                    ^^^^^^^^^^^^^^^^^^^^^^^
    help: remove this attribute
      --> src/c_char.rs:55:36
       |
    55 |         all(target_os = "fuchsia", target_arch = "aarch64")
       |                                    ^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

    warning: `cxx` (lib) generated 15 warnings
@GuillaumeGomez
Copy link
Member

You're right, it should not check cfg like this.

@SteveLauC
Copy link

Here is another false positive case found in Nix:

https://github.com/nix-rust/nix/blob/01cd697b82087730b00bafa60e25fd53b025cfdd/src/sys/statfs.rs#L77-L79

#[cfg(any(
    target_os = "freebsd",
    target_os = "android",
    all(target_os = "linux", target_arch = "s390x"),
    all(target_os = "linux", target_env = "musl"),
    all(target_os = "linux", target_env = "ohos"),
    all(
        target_os = "linux",
        not(any(target_arch = "s390x", target_env = "musl"))
    ),
))]
#[derive(Eq, Copy, Clone, PartialEq, Debug)]
pub struct FsType(pub fs_type_t);

Clippy suggests me to remove these "duplicate" linux attributes even though that they are actually not the same thing.

Full log here: https://github.com/nix-rust/nix/blob/01cd697b82087730b00bafa60e25fd53b025cfdd/src/sys/statfs.rs#L77-L79

@tamird
Copy link
Contributor

tamird commented Mar 24, 2024

There's also a false positive when using https://crates.io/crates/test-case.

#[test_case("pointer", false, None, 42)]
#[test_case("pointer", true, None, 21)]
#[test_case("struct_flavors", false, None, 1)]
#[test_case("struct_flavors", true, None, 2)]
fn relocation_tests(
    program: &str,
    with_relocations: bool,
    required_kernel_version: Option<(KernelVersion, &str)>,
    expected: u64,
) {
  ...
}
help: remove this attribute
  --> test/integration-test/src/tests/btf_relocations.rs:23:30
   |
23 | #[test_case("pointer", true, None, 21)]
   |                              ^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

warning: duplicated attribute
  --> test/integration-test/src/tests/btf_relocations.rs:24:38
   |
24 | #[test_case("struct_flavors", false, None, 1)]
   |                                      ^^^^
   |
note: first defined here
  --> test/integration-test/src/tests/btf_relocations.rs:12:40
   |
12 | #[test_case("enum_unsigned_32", false, None, 0xAAAAAAAA)]
   |                                        ^^^^
help: remove this attribute
  --> test/integration-test/src/tests/btf_relocations.rs:24:38
   |
24 | #[test_case("struct_flavors", false, None, 1)]
   |                                      ^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

warning: duplicated attribute
  --> test/integration-test/src/tests/btf_relocations.rs:25:37
   |
25 | #[test_case("struct_flavors", true, None, 2)]
   |                                     ^^^^
   |
note: first defined here
  --> test/integration-test/src/tests/btf_relocations.rs:12:40
   |
12 | #[test_case("enum_unsigned_32", false, None, 0xAAAAAAAA)]
   |                                        ^^^^
help: remove this attribute
  --> test/integration-test/src/tests/btf_relocations.rs:25:37
   |
25 | #[test_case("struct_flavors", true, None, 2)]
   |                                     ^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

warning: `integration-test` (lib test) generated 9 warnings

@GuillaumeGomez
Copy link
Member

Normally #12555 should fix both your cases since it's a late pass expansion, but please double-check @tamird once it's merged and the new clippy version published.

bors added a commit that referenced this issue Mar 26, 2024
Don't emit `duplicated_attribute` lint on "complex" `cfg`s

Part of #12537.

changelog: Don't emit `duplicated_attribute` lint on "complex" `cfg`s
@tamird
Copy link
Contributor

tamird commented Mar 27, 2024

@GuillaumeGomez it'd be helpful if you pinged this issue when a new nightly is out with this fix.

taiki-e added a commit to taiki-e/portable-atomic that referenced this issue Mar 27, 2024
rust-lang/rust-clippy#12537
rust-lang/rust-clippy#12538

```
error: duplicated attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:21
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
      = note: `-D clippy::duplicated-attributes` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`

  error: duplicated attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:46
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:173:13
      |
  173 |             portable_atomic_unstable_asm_experimental_arch,
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:195:5
      |
  195 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:196:5
      |
  196 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:194:5
      |
  194 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
```
taiki-e added a commit to taiki-e/portable-atomic that referenced this issue Mar 27, 2024
rust-lang/rust-clippy#12537
rust-lang/rust-clippy#12538

```
error: duplicated attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:21
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
      = note: `-D clippy::duplicated-attributes` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`

  error: duplicated attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:46
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:173:13
      |
  173 |             portable_atomic_unstable_asm_experimental_arch,
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:195:5
      |
  195 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:196:5
      |
  196 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:194:5
      |
  194 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
```
taiki-e added a commit to taiki-e/portable-atomic that referenced this issue Mar 27, 2024
rust-lang/rust-clippy#12537
rust-lang/rust-clippy#12538

```
error: duplicated attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:21
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:21
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
      = note: `-D clippy::duplicated-attributes` implied by `-D warnings`
      = help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`

  error: duplicated attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:164:46
      |
  164 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:168:46
      |
  168 |             any(not(portable_atomic_no_asm), portable_atomic_unstable_asm),
      |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:173:13
      |
  173 |             portable_atomic_unstable_asm_experimental_arch,
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:179:36
      |
  179 |         all(target_arch = "s390x", portable_atomic_unstable_asm_experimental_arch),
      |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:195:5
      |
  195 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:205:5
      |
  205 |     target_arch = "avr",
      |     ^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:196:5
      |
  196 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:206:5
      |
  206 |     target_arch = "msp430",
      |     ^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

  error: duplicated attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
  note: first defined here
     --> src\imp\mod.rs:194:5
      |
  194 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  help: remove this attribute
     --> src\imp\mod.rs:210:5
      |
  210 |     feature = "critical-section",
      |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
```
@GuillaumeGomez
Copy link
Member

I can ask @flip1995 for that when he does it. :)

@flip1995
Copy link
Member

2024-04-05

@tamird
Copy link
Contributor

tamird commented Apr 7, 2024

Looks like #12555 did not fix this issue. Tested with rustc 1.79.0-nightly (aa1c45908 2024-04-06) which includes #12555 as rust-lang/rust@e3f3a4b.

GuillaumeGomez added a commit to GuillaumeGomez/rust-clippy that referenced this issue Apr 8, 2024
@GuillaumeGomez
Copy link
Member

Just tested locally and can't reproduce it. Just in case, I opened #12646 to ensure that attributes generated by proc-macros don't emit a warning.

@tamird
Copy link
Contributor

tamird commented Apr 8, 2024

I'm able to reproduce with yesterday's (2024-04-07) nightly as well. If you want, you can revert aya-rs/aya@b552c83 locally and then run cargo +nightly clippy --all-targets --workspace --target x86_64-unknown-linux-gnu -- --deny warnings from the root of the repository.

@GuillaumeGomez
Copy link
Member

I'm starting to wonder if proc-macros don't need special treatment here...

@blyxyas
Copy link
Member

blyxyas commented Apr 8, 2024

I'll do some testing =^w^=

@blyxyas
Copy link
Member

blyxyas commented Apr 8, 2024

I am also having these issues. It seems like the current master still lints on it. You can try it by cloning the aya repo, pulling master and doing the following command:

cargo dev lint ../aya -- --all-targets --workspace --target x86_64-unknown-linux-gnu

@GuillaumeGomez
Copy link
Member

Ok so that confirms that some tokens are not marked as "from expansion" in proc-macros. Gonna investigate a bit more.

@la10736
Copy link

la10736 commented Apr 9, 2024

Also on rstest we have the same issue : la10736/rstest#238

warning: duplicated attribute
  --> src/main.rs:13:14
   |
13 | #[case(None, None)] // warns
   |              ^^^^
   |
note: first defined here
  --> src/main.rs:13:8
   |
13 | #[case(None, None)] // warns
   |        ^^^^
help: remove this attribute
  --> src/main.rs:13:14
   |
13 | #[case(None, None)] // warns
   |              ^^^^
   = 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
  --> src/main.rs:14:17
   |
14 | #[case(Some(1), None)] // warns
   |                 ^^^^
   |
note: first defined here
  --> src/main.rs:13:8
   |
13 | #[case(None, None)] // warns
   |        ^^^^
help: remove this attribute
  --> src/main.rs:14:17
   |
14 | #[case(Some(1), None)] // warns
   |                 ^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes

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

warning: `rstest_238` (bin "rstest_238") generated 3 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.38s
mdamico@miklap:~/dev_random/rstest_238$ cargo +nightly clippy --version
clippy 0.1.79 (ab5bda1 2024-04-08)

@GuillaumeGomez
Copy link
Member

Yes got it. Still trying to write a minimal code to reproduce the bug.

@blyxyas
Copy link
Member

blyxyas commented Apr 9, 2024

I tested #12646, and this should be fixed when that hits nightly :)

bors added a commit that referenced this issue Apr 9, 2024
Turn `duplicated_attributes` into a late lint

Fixes #12537.

changelog: Turn `duplicated_attributes` into a late lint
@bors bors closed this as completed in 62fd1d5 Apr 9, 2024
@la10736
Copy link

la10736 commented Apr 14, 2024

@GuillaumeGomez Still have the issue also on the last nightly

mdamico@miklap:~/dev_random/rstest_238$ cargo +nightly clippy --version
clippy 0.1.79 (0bf471f 2024-04-13)

Clippy behaviour is still the same of #12537 (comment)

@la10736
Copy link

la10736 commented Apr 14, 2024

@tamird I guess that also for test_case the issue is still unresolved with clippy 0.1.79 (0bf471f 2024-04-13).

@GuillaumeGomez
Copy link
Member

Then please provide a minimal code I can use to reproduce the bug and fix it (and also use as regression test).

@y21
Copy link
Member

y21 commented Apr 14, 2024

Worth noting that the last change here (#12646) is, again, not on nightly yet, since the clippy subtree is only updated every 2 weeks. So it's entirely possible that it is fixed, just not on nightly yet and so we can't do anything but wait. It'd be useful to also run master clippy on the crate (like here) and see what happens there.

@blyxyas
Copy link
Member

blyxyas commented Apr 15, 2024

I second y21's comment. If you're open to some testing, clone the repo (or pull master) and test it with a similar command. If that doesn't work, please report back! ❤️

@la10736
Copy link

la10736 commented Apr 23, 2024

@GuillaumeGomez I tested with clippy 0.1.79 (7f2fc33 2024-04-22) and now it's works!!!

Thanks!!!

@GuillaumeGomez
Copy link
Member

Perfect. :)

Closing then!

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 I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants