Rollup merge of #147683 - jdonszelmann:less-duplicate-checking, r=JonathanBrouwer

only check duplicates on old/unparsed attributes

r? ``@JonathanBrouwer``

This was effectively already what we were doing, but this was implicit because `.name()` etc were just returning None when dealing with a parsed attribute.... this makes it explicit
This commit is contained in:
Matthias Krüger 2025-10-14 19:47:35 +02:00 committed by GitHub
commit 545ee6fe6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -395,8 +395,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
let builtin = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name));
if hir_id != CRATE_HIR_ID {
match attr {
Attribute::Parsed(_) => { /* Already validated. */ }
@ -442,8 +440,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
if let Some(BuiltinAttribute { duplicates, .. }) = builtin {
check_duplicates(self.tcx, attr, hir_id, *duplicates, &mut seen);
if let Attribute::Unparsed(unparsed_attr) = attr
&& let Some(BuiltinAttribute { duplicates, .. }) =
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name))
{
check_duplicates(
self.tcx,
unparsed_attr.span,
attr,
hir_id,
*duplicates,
&mut seen,
);
}
self.check_unused_attribute(hir_id, attr, style)
@ -2478,6 +2486,7 @@ pub(crate) fn provide(providers: &mut Providers) {
// FIXME(jdonszelmann): remove, check during parsing
fn check_duplicates(
tcx: TyCtxt<'_>,
attr_span: Span,
attr: &Attribute,
hir_id: HirId,
duplicates: AttributeDuplicates,
@ -2494,10 +2503,10 @@ fn check_duplicates(
match seen.entry(attr_name) {
Entry::Occupied(mut entry) => {
let (this, other) = if matches!(duplicates, FutureWarnPreceding) {
let to_remove = entry.insert(attr.span());
(to_remove, attr.span())
let to_remove = entry.insert(attr_span);
(to_remove, attr_span)
} else {
(attr.span(), *entry.get())
(attr_span, *entry.get())
};
tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
@ -2514,22 +2523,22 @@ fn check_duplicates(
);
}
Entry::Vacant(entry) => {
entry.insert(attr.span());
entry.insert(attr_span);
}
}
}
ErrorFollowing | ErrorPreceding => match seen.entry(attr_name) {
Entry::Occupied(mut entry) => {
let (this, other) = if matches!(duplicates, ErrorPreceding) {
let to_remove = entry.insert(attr.span());
(to_remove, attr.span())
let to_remove = entry.insert(attr_span);
(to_remove, attr_span)
} else {
(attr.span(), *entry.get())
(attr_span, *entry.get())
};
tcx.dcx().emit_err(errors::UnusedMultiple { this, other, name: attr_name });
}
Entry::Vacant(entry) => {
entry.insert(attr.span());
entry.insert(attr_span);
}
},
}