You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
duplicated_attributes lint no longer emitted for #[cfg(test)] when switching from 1.93 -> 1.94 #16852
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)fnsome_util() -> u64{42}}#[cfg(test)]#[test]fnmy_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.
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
When I have a little more time and energy I'll think about what a nice solution for this is, because I'd love if we wouldn't have to special-case trace attributes. I'll claim this issue to keep it on my backlog, but might take a while for me to get around to it, so if anyone feels like doing it feel free to steal my claim @rustbot claim
Activity
obi1kenobi commentedon Apr 14, 2026
While poking around for what changed in 1.94, I noticed this PR which seems to likely be relevant here: rust-lang/rust#150310
cc @jdonszelmann @JonathanBrouwer for visibility
JonathanBrouwer commentedon Apr 15, 2026
This is because trace attributes are now a little special in the AST, for performance reasons they are stored in a parsed form, so this check returns None: https://github.com/rust-lang/rust/blob/d9385437c20f4f7fb60fced9dd2d2d37a004dcf4/src/tools/clippy/clippy_lints/src/attrs/duplicated_attributes.rs#L86
When I have a little more time and energy I'll think about what a nice solution for this is, because I'd love if we wouldn't have to special-case trace attributes. I'll claim this issue to keep it on my backlog, but might take a while for me to get around to it, so if anyone feels like doing it feel free to steal my claim
@rustbot claim