Closed
Description
Summary
When two lint reasons are the same, duplicated_attributes
lints and suggests that one of them should be removed. This would change the meaning.
Besides the specific case of allow(..., reason = ...)
, I also observe that the implementation seems to be making the assumption that, unless otherwise specified, all attributes’ syntax can be interpreted as a tree of shared prefixes like use foo::{bar, baz}
is. That's not true; it's up to the attribute’s definition how its contents are interpreted. If that false assumption were removed, then #13238 would also be fixed, and #12619 (rustc_on_unimplemented
) wouldn't need a special case.
Lint Name
duplicated_attributes
Reproducer
I tried this code:
#![allow(missing_docs, reason = "library for internal use only")]
#![allow(
exported_private_dependencies,
reason = "library for internal use only"
)]
I saw this happen:
warning: duplicated attribute
--> src/lib.rs:4:5
|
4 | reason = "library for internal use only"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: first defined here
--> src/lib.rs:1:24
|
1 | #![allow(missing_docs, reason = "library for internal use only")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: remove this attribute
--> src/lib.rs:4:5
|
4 | reason = "library for internal use only"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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
Expected: No lint
Version
rustc 1.83.0-nightly (4ac7bcbaa 2024-09-04)
binary: rustc
commit-hash: 4ac7bcbaad8d6fd7a51bdf1b696cbc3ba4c796cf
commit-date: 2024-09-04
host: x86_64-apple-darwin
release: 1.83.0-nightly
LLVM version: 19.1.0
Additional Labels
No response