Skip to content

Commit 412b691

Browse files
committed
Auto merge of #12620 - Nilstrieb:dupattr, r=xFrednet
Handle `rustc_on_unimplemented` in duplicated_attributes ```rust #[rustc_on_unimplemented( on( _Self = "&str", label = "`a" ), on( _Self = "alloc::string::String", label = "a" ), )] ``` The lint treats this as a repetition because `rustc_on_unimplemented::on::label` appears twice, but that's ok. Fixes #12619 changelog: [`duplicated_attributes`]: fix handling of `rustc_on_unimplemented`
2 parents 0e5bded + b10be16 commit 412b691

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
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

0 commit comments

Comments
 (0)