@@ -191,6 +191,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
191191 Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
192192 self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
193193 }
194+ Attribute :: Parsed ( AttributeKind :: LinkName { span : attr_span, name } ) => {
195+ self . check_link_name ( hir_id, * attr_span, * name, span, target)
196+ }
194197 Attribute :: Parsed ( AttributeKind :: MayDangle ( attr_span) ) => {
195198 self . check_may_dangle ( hir_id, * attr_span)
196199 }
@@ -283,7 +286,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
283286 [ sym:: ffi_const, ..] => self . check_ffi_const ( attr. span ( ) , target) ,
284287 [ sym:: link_ordinal, ..] => self . check_link_ordinal ( attr, span, target) ,
285288 [ sym:: link, ..] => self . check_link ( hir_id, attr, span, target) ,
286- [ sym:: link_name, ..] => self . check_link_name ( hir_id, attr, span, target) ,
287289 [ sym:: link_section, ..] => self . check_link_section ( hir_id, attr, span, target) ,
288290 [ sym:: macro_use, ..] | [ sym:: macro_escape, ..] => {
289291 self . check_macro_use ( hir_id, attr, target)
@@ -1604,35 +1606,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16041606 }
16051607
16061608 /// Checks if `#[link_name]` is applied to an item other than a foreign function or static.
1607- fn check_link_name ( & self , hir_id : HirId , attr : & Attribute , span : Span , target : Target ) {
1609+ fn check_link_name (
1610+ & self ,
1611+ hir_id : HirId ,
1612+ attr_span : Span ,
1613+ name : Symbol ,
1614+ span : Span ,
1615+ target : Target ,
1616+ ) {
16081617 match target {
16091618 Target :: ForeignFn | Target :: ForeignStatic => { }
16101619 // FIXME(#80564): We permit struct fields, match arms and macro defs to have an
16111620 // `#[link_name]` attribute with just a lint, because we previously
16121621 // erroneously allowed it and some crates used it accidentally, to be compatible
16131622 // with crates depending on them, we can't throw an error here.
16141623 Target :: Field | Target :: Arm | Target :: MacroDef => {
1615- self . inline_attr_str_error_with_macro_def ( hir_id, attr . span ( ) , "link_name" ) ;
1624+ self . inline_attr_str_error_with_macro_def ( hir_id, attr_span , "link_name" ) ;
16161625 }
16171626 _ => {
1618- // FIXME: #[cold ] was previously allowed on non-functions/statics and some crates
1627+ // FIXME: #[link_name ] was previously allowed on non-functions/statics and some crates
16191628 // used this, so only emit a warning.
1620- let attr_span = matches ! ( target, Target :: ForeignMod ) . then_some ( attr. span ( ) ) ;
1621- if let Some ( s) = attr. value_str ( ) {
1622- self . tcx . emit_node_span_lint (
1623- UNUSED_ATTRIBUTES ,
1624- hir_id,
1625- attr. span ( ) ,
1626- errors:: LinkName { span, attr_span, value : s. as_str ( ) } ,
1627- ) ;
1628- } else {
1629- self . tcx . emit_node_span_lint (
1630- UNUSED_ATTRIBUTES ,
1631- hir_id,
1632- attr. span ( ) ,
1633- errors:: LinkName { span, attr_span, value : "..." } ,
1634- ) ;
1635- } ;
1629+ let help_span = matches ! ( target, Target :: ForeignMod ) . then_some ( attr_span) ;
1630+ self . tcx . emit_node_span_lint (
1631+ UNUSED_ATTRIBUTES ,
1632+ hir_id,
1633+ attr_span,
1634+ errors:: LinkName { span, help_span, value : name. as_str ( ) } ,
1635+ ) ;
16361636 }
16371637 }
16381638 }
0 commit comments