Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,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. */ }
Expand Down Expand Up @@ -440,8 +438,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)
Expand Down Expand Up @@ -2481,6 +2489,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,
Expand All @@ -2497,10 +2506,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,
Expand All @@ -2517,22 +2526,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);
}
},
}
Expand Down
Loading