@@ -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
24792487fn 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