Skip to content

Prefixed attributes are not detected as duplicated #14942

Open
@samueltardieu

Description

@samueltardieu

Summary

Although the mechanism for checking inner meta items is present in the lint logic, it doesn't properly account for the fact that inner meta items will not have their name (which contains, e.g., allow, deny, etc.) set when recursing.

Found while working on #14855.

@rustbot label "+good first issue"

Lint Name

duplicated_attributes

Reproducer

I tried this code:

#![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)]

fn main() {}

I expected to see this happen: two errors, one for the duplication of #![deny(unused)], and one for the duplication of #![deny(clippy::dupplicated_attributes)].

Instead, this happened:

Only the duplication of #[deny(unused)] is detected.

error: duplicated attribute
 --> /tmp/t.rs:1:17
  |
1 | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)]
  |                 ^^^^^^
  |
note: first defined here
 --> /tmp/t.rs:1:9
  |
1 | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)]
  |         ^^^^^^
help: remove this attribute
 --> /tmp/t.rs:1:17
  |
1 | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)]
  |                 ^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#duplicated_attributes
note: the lint level is defined here
 --> /tmp/t.rs:1:56
  |
1 | #![deny(unused, unused, clippy::duplicated_attributes, clippy::duplicated_attributes)]
  |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Version

rustc 1.89.0-nightly (70b3f4666 2025-05-30)
binary: rustc
commit-hash: 70b3f4666e24ce22fc32f5e357dbcf85d3254e63
commit-date: 2025-05-30
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tgood first issueThese issues are a good way to get started with Clippy

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions