Skip to content

Commit 545ee6f

Browse files
authored
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
2 parents ea0c8d8 + a51a793 commit 545ee6f

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
395395
}
396396
}
397397

398-
let builtin = attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name));
399-
400398
if hir_id != CRATE_HIR_ID {
401399
match attr {
402400
Attribute::Parsed(_) => { /* Already validated. */ }
@@ -442,8 +440,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
442440
}
443441
}
444442

445-
if let Some(BuiltinAttribute { duplicates, .. }) = builtin {
446-
check_duplicates(self.tcx, attr, hir_id, *duplicates, &mut seen);
443+
if let Attribute::Unparsed(unparsed_attr) = attr
444+
&& let Some(BuiltinAttribute { duplicates, .. }) =
445+
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name))
446+
{
447+
check_duplicates(
448+
self.tcx,
449+
unparsed_attr.span,
450+
attr,
451+
hir_id,
452+
*duplicates,
453+
&mut seen,
454+
);
447455
}
448456

449457
self.check_unused_attribute(hir_id, attr, style)
@@ -2478,6 +2486,7 @@ pub(crate) fn provide(providers: &mut Providers) {
24782486
// FIXME(jdonszelmann): remove, check during parsing
24792487
fn check_duplicates(
24802488
tcx: TyCtxt<'_>,
2489+
attr_span: Span,
24812490
attr: &Attribute,
24822491
hir_id: HirId,
24832492
duplicates: AttributeDuplicates,
@@ -2494,10 +2503,10 @@ fn check_duplicates(
24942503
match seen.entry(attr_name) {
24952504
Entry::Occupied(mut entry) => {
24962505
let (this, other) = if matches!(duplicates, FutureWarnPreceding) {
2497-
let to_remove = entry.insert(attr.span());
2498-
(to_remove, attr.span())
2506+
let to_remove = entry.insert(attr_span);
2507+
(to_remove, attr_span)
24992508
} else {
2500-
(attr.span(), *entry.get())
2509+
(attr_span, *entry.get())
25012510
};
25022511
tcx.emit_node_span_lint(
25032512
UNUSED_ATTRIBUTES,
@@ -2514,22 +2523,22 @@ fn check_duplicates(
25142523
);
25152524
}
25162525
Entry::Vacant(entry) => {
2517-
entry.insert(attr.span());
2526+
entry.insert(attr_span);
25182527
}
25192528
}
25202529
}
25212530
ErrorFollowing | ErrorPreceding => match seen.entry(attr_name) {
25222531
Entry::Occupied(mut entry) => {
25232532
let (this, other) = if matches!(duplicates, ErrorPreceding) {
2524-
let to_remove = entry.insert(attr.span());
2525-
(to_remove, attr.span())
2533+
let to_remove = entry.insert(attr_span);
2534+
(to_remove, attr_span)
25262535
} else {
2527-
(attr.span(), *entry.get())
2536+
(attr_span, *entry.get())
25282537
};
25292538
tcx.dcx().emit_err(errors::UnusedMultiple { this, other, name: attr_name });
25302539
}
25312540
Entry::Vacant(entry) => {
2532-
entry.insert(attr.span());
2541+
entry.insert(attr_span);
25332542
}
25342543
},
25352544
}

0 commit comments

Comments
 (0)