Skip to content

Commit 1f9e392

Browse files
committed
Handle rustc_on_unimplemented in duplicated_attributes
1 parent 852a64f commit 1f9e392

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

clippy_lints/src/attrs/duplicated_attributes.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ fn check_duplicated_attr(
3636
}
3737
let Some(ident) = attr.ident() else { return };
3838
let name = ident.name;
39-
if name == sym::doc || name == sym::cfg_attr {
39+
if name == sym::doc || name == sym::cfg_attr || name == sym::rustc_on_unimplemented {
4040
// FIXME: Would be nice to handle `cfg_attr` as well. Only problem is to check that cfg
4141
// conditions are the same.
42+
// `#[rustc_on_unimplemented]` contains duplicated subattributes, that's expected.
4243
return;
4344
}
4445
if let Some(direct_parent) = parent.last()

tests/ui/duplicated_attributes.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@aux-build:proc_macro_attr.rs
2-
2+
#![feature(rustc_attrs)]
33
#![warn(clippy::duplicated_attributes)]
44
#![cfg(any(unix, windows))]
55
#![allow(dead_code)]
@@ -20,6 +20,10 @@ fn foo() {}
2020
#[cfg(unix)] // cfgs are not handled
2121
fn bar() {}
2222

23+
// No warning:
24+
#[rustc_on_unimplemented(on(_Self = "&str", label = "`a"), on(_Self = "alloc::string::String", label = "a"))]
25+
trait Abc {}
26+
2327
#[proc_macro_attr::duplicated_attr()] // Should not warn!
2428
fn babar() {}
2529

tests/ui/duplicated_attributes.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error: duplicated attribute
2-
--> tests/ui/duplicated_attributes.rs:6:10
2+
--> tests/ui/duplicated_attributes.rs:7:10
33
|
44
LL | #![allow(dead_code)]
55
| ^^^^^^^^^
66
|
77
note: first defined here
8-
--> tests/ui/duplicated_attributes.rs:5:10
8+
--> tests/ui/duplicated_attributes.rs:6:10
99
|
1010
LL | #![allow(dead_code)]
1111
| ^^^^^^^^^
1212
help: remove this attribute
13-
--> tests/ui/duplicated_attributes.rs:6:10
13+
--> tests/ui/duplicated_attributes.rs:7:10
1414
|
1515
LL | #![allow(dead_code)]
1616
| ^^^^^^^^^
1717
= note: `-D clippy::duplicated-attributes` implied by `-D warnings`
1818
= help: to override `-D warnings` add `#[allow(clippy::duplicated_attributes)]`
1919

2020
error: duplicated attribute
21-
--> tests/ui/duplicated_attributes.rs:14:9
21+
--> tests/ui/duplicated_attributes.rs:15:9
2222
|
2323
LL | #[allow(dead_code)]
2424
| ^^^^^^^^^
2525
|
2626
note: first defined here
27-
--> tests/ui/duplicated_attributes.rs:13:9
27+
--> tests/ui/duplicated_attributes.rs:14:9
2828
|
2929
LL | #[allow(dead_code)]
3030
| ^^^^^^^^^
3131
help: remove this attribute
32-
--> tests/ui/duplicated_attributes.rs:14:9
32+
--> tests/ui/duplicated_attributes.rs:15:9
3333
|
3434
LL | #[allow(dead_code)]
3535
| ^^^^^^^^^

0 commit comments

Comments
 (0)