@@ -191,6 +191,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
191
191
Attribute :: Parsed ( AttributeKind :: AsPtr ( attr_span) ) => {
192
192
self . check_applied_to_fn_or_method ( hir_id, * attr_span, span, target)
193
193
}
194
+ Attribute :: Parsed ( AttributeKind :: LinkName { span : attr_span, name } ) => {
195
+ self . check_link_name ( hir_id, * attr_span, * name, span, target)
196
+ }
194
197
Attribute :: Parsed ( AttributeKind :: MayDangle ( attr_span) ) => {
195
198
self . check_may_dangle ( hir_id, * attr_span)
196
199
}
@@ -283,7 +286,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
283
286
[ sym:: ffi_const, ..] => self . check_ffi_const ( attr. span ( ) , target) ,
284
287
[ sym:: link_ordinal, ..] => self . check_link_ordinal ( attr, span, target) ,
285
288
[ sym:: link, ..] => self . check_link ( hir_id, attr, span, target) ,
286
- [ sym:: link_name, ..] => self . check_link_name ( hir_id, attr, span, target) ,
287
289
[ sym:: link_section, ..] => self . check_link_section ( hir_id, attr, span, target) ,
288
290
[ sym:: macro_use, ..] | [ sym:: macro_escape, ..] => {
289
291
self . check_macro_use ( hir_id, attr, target)
@@ -1604,35 +1606,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1604
1606
}
1605
1607
1606
1608
/// 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
+ ) {
1608
1617
match target {
1609
1618
Target :: ForeignFn | Target :: ForeignStatic => { }
1610
1619
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
1611
1620
// `#[link_name]` attribute with just a lint, because we previously
1612
1621
// erroneously allowed it and some crates used it accidentally, to be compatible
1613
1622
// with crates depending on them, we can't throw an error here.
1614
1623
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" ) ;
1616
1625
}
1617
1626
_ => {
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
1619
1628
// 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
+ ) ;
1636
1636
}
1637
1637
}
1638
1638
}
0 commit comments