Summary
Duplicating #[cfg(test)] between a module's declaration in lib.rs and its contents (either as a separate file or inlined) no longer raises clippy::duplicated_attributes in Rust 1.94+. This is a regression from 1.93.1 and earlier. Please see repro below.
Lint Name
duplicated_attributes
Reproducer
I tried this code:
#[cfg(test)]
#[allow(clippy::mixed_attributes_style, reason = "normally the module is a separate file; inlined here for simplicity")]
mod test_util {
#![expect(
clippy::duplicated_attributes,
reason = "defensively specifying cfg(test) both inside `test_util.rs` and when the module is declared in `mod.rs`"
)]
#![cfg(test)]
pub(crate) fn some_util() -> u64 {
42
}
}
#[cfg(test)]
#[test]
fn my_test() {
assert_eq!(test_util::some_util(), 42);
}
I expected to see this happen: clippy::duplicated_attributes is raised, matching the behavior of clippy in Rust 1.93 and earlier.
$ cargo +1.93 clippy --all-targets -- -Dwarnings
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
Instead, this happened: clippy::duplicated_attributes is not raised, and the lint expectation is unfulfilled.
$ cargo +stable clippy --all-targets -- -Dwarnings
Checking example v0.1.0 (/tmp/example)
error: this lint expectation is unfulfilled
--> src/lib.rs:5:9
|
5 | clippy::duplicated_attributes,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: defensively specifying cfg(test) both inside `test_util.rs` and when the module is declared in `mod.rs`
= note: `-D unfulfilled-lint-expectations` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unfulfilled_lint_expectations)]`
error: could not compile `example` (lib test) due to 1 previous error
Version
rustc 1.94.0 (4a4ef493e 2026-03-02)
binary: rustc
commit-hash: 4a4ef493e3a1488c6e321570238084b38948f6db
commit-date: 2026-03-02
host: x86_64-unknown-linux-gnu
release: 1.94.0
LLVM version: 21.1.8
$ cargo +stable clippy --version
clippy 0.1.94 (4a4ef493e3 2026-03-02)
Summary
Duplicating
#[cfg(test)]between a module's declaration inlib.rsand its contents (either as a separate file or inlined) no longer raisesclippy::duplicated_attributesin Rust 1.94+. This is a regression from 1.93.1 and earlier. Please see repro below.Lint Name
duplicated_attributesReproducer
I tried this code:
I expected to see this happen:
clippy::duplicated_attributesis raised, matching the behavior of clippy in Rust 1.93 and earlier.Instead, this happened:
clippy::duplicated_attributesis not raised, and the lint expectation is unfulfilled.Version