Skip to content

Commit 558f468

Browse files
committed
Handle rustc_on_unimplemented in duplicated_attributes
1 parent f9f854f commit 558f468

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

clippy_lints/src/attrs/duplicated_attributes.rs

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

tests/ui/duplicated_attributes.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(clippy::duplicated_attributes)]
2+
#![feature(rustc_attrs)]
23
#![cfg(any(unix, windows))]
34
#![allow(dead_code)]
45
#![allow(dead_code)] //~ ERROR: duplicated attribute
@@ -15,4 +16,17 @@ fn foo() {}
1516
#[cfg(unix)] //~ ERROR: duplicated attribute
1617
fn bar() {}
1718

19+
// No warning:
20+
#[rustc_on_unimplemented(
21+
on(
22+
_Self = "&str",
23+
label = "`a"
24+
),
25+
on(
26+
_Self = "alloc::string::String",
27+
label = "a"
28+
),
29+
)]
30+
trait Abc {}
31+
1832
fn main() {}

tests/ui/duplicated_attributes.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
error: duplicated attribute
2-
--> tests/ui/duplicated_attributes.rs:4:10
2+
--> tests/ui/duplicated_attributes.rs:5:10
33
|
44
LL | #![allow(dead_code)]
55
| ^^^^^^^^^
66
|
77
note: first defined here
8-
--> tests/ui/duplicated_attributes.rs:3:10
8+
--> tests/ui/duplicated_attributes.rs:4:10
99
|
1010
LL | #![allow(dead_code)]
1111
| ^^^^^^^^^
1212
help: remove this attribute
13-
--> tests/ui/duplicated_attributes.rs:4:10
13+
--> tests/ui/duplicated_attributes.rs:5: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:9:9
21+
--> tests/ui/duplicated_attributes.rs:10:9
2222
|
2323
LL | #[allow(dead_code)]
2424
| ^^^^^^^^^
2525
|
2626
note: first defined here
27-
--> tests/ui/duplicated_attributes.rs:8:9
27+
--> tests/ui/duplicated_attributes.rs:9:9
2828
|
2929
LL | #[allow(dead_code)]
3030
| ^^^^^^^^^
3131
help: remove this attribute
32-
--> tests/ui/duplicated_attributes.rs:9:9
32+
--> tests/ui/duplicated_attributes.rs:10:9
3333
|
3434
LL | #[allow(dead_code)]
3535
| ^^^^^^^^^
3636

3737
error: duplicated attribute
38-
--> tests/ui/duplicated_attributes.rs:15:7
38+
--> tests/ui/duplicated_attributes.rs:16:7
3939
|
4040
LL | #[cfg(unix)]
4141
| ^^^^
4242
|
4343
note: first defined here
44-
--> tests/ui/duplicated_attributes.rs:13:7
44+
--> tests/ui/duplicated_attributes.rs:14:7
4545
|
4646
LL | #[cfg(unix)]
4747
| ^^^^
4848
help: remove this attribute
49-
--> tests/ui/duplicated_attributes.rs:15:7
49+
--> tests/ui/duplicated_attributes.rs:16:7
5050
|
5151
LL | #[cfg(unix)]
5252
| ^^^^

0 commit comments

Comments
 (0)