Skip to content

Commit

Permalink
Handle rustc_on_unimplemented in duplicated_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilstrieb committed May 1, 2024
1 parent 852a64f commit 1f9e392
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion clippy_lints/src/attrs/duplicated_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ fn check_duplicated_attr(
}
let Some(ident) = attr.ident() else { return };
let name = ident.name;
if name == sym::doc || name == sym::cfg_attr {
if name == sym::doc || name == sym::cfg_attr || name == sym::rustc_on_unimplemented {
// FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg
// conditions are the same.
// `#[rustc_on_unimplemented]` contains duplicated subattributes, that's expected.
return;
}
if let Some(direct_parent) = parent.last()
Expand Down
6 changes: 5 additions & 1 deletion tests/ui/duplicated_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@aux-build:proc_macro_attr.rs

#![feature(rustc_attrs)]
#![warn(clippy::duplicated_attributes)]
#![cfg(any(unix, windows))]
#![allow(dead_code)]
Expand All @@ -20,6 +20,10 @@ fn foo() {}
#[cfg(unix)] // cfgs are not handled
fn bar() {}

// No warning:
#[rustc_on_unimplemented(on(_Self = "&str", label = "`a"), on(_Self = "alloc::string::String", label = "a"))]
trait Abc {}

#[proc_macro_attr::duplicated_attr()] // Should not warn!
fn babar() {}

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/duplicated_attributes.stderr
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
error: duplicated attribute
--> tests/ui/duplicated_attributes.rs:6:10
--> tests/ui/duplicated_attributes.rs:7:10
|
LL | #![allow(dead_code)]
| ^^^^^^^^^
|
note: first defined here
--> tests/ui/duplicated_attributes.rs:5:10
--> tests/ui/duplicated_attributes.rs:6:10
|
LL | #![allow(dead_code)]
| ^^^^^^^^^
help: remove this attribute
--> tests/ui/duplicated_attributes.rs:6:10
--> tests/ui/duplicated_attributes.rs:7:10
|
LL | #![allow(dead_code)]
| ^^^^^^^^^
= note: `-D clippy::duplicated-attributes` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`

error: duplicated attribute
--> tests/ui/duplicated_attributes.rs:14:9
--> tests/ui/duplicated_attributes.rs:15:9
|
LL | #[allow(dead_code)]
| ^^^^^^^^^
|
note: first defined here
--> tests/ui/duplicated_attributes.rs:13:9
--> tests/ui/duplicated_attributes.rs:14:9
|
LL | #[allow(dead_code)]
| ^^^^^^^^^
help: remove this attribute
--> tests/ui/duplicated_attributes.rs:14:9
--> tests/ui/duplicated_attributes.rs:15:9
|
LL | #[allow(dead_code)]
| ^^^^^^^^^
Expand Down

0 comments on commit 1f9e392

Please sign in to comment.