@@ -149,6 +149,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
149
149
}
150
150
Attribute :: Parsed ( AttributeKind :: Repr ( _) ) => { /* handled below this loop and elsewhere */
151
151
}
152
+ Attribute :: Parsed ( AttributeKind :: Cold ( attr_span) ) => {
153
+ self . check_cold ( hir_id, * attr_span, span, target)
154
+ }
152
155
Attribute :: Parsed (
153
156
AttributeKind :: BodyStability { .. }
154
157
| AttributeKind :: ConstStabilityIndirect
@@ -241,7 +244,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
241
244
[ sym:: ffi_pure, ..] => self . check_ffi_pure ( attr. span ( ) , attrs, target) ,
242
245
[ sym:: ffi_const, ..] => self . check_ffi_const ( attr. span ( ) , target) ,
243
246
[ sym:: link_ordinal, ..] => self . check_link_ordinal ( attr, span, target) ,
244
- [ sym:: cold, ..] => self . check_cold ( hir_id, attr, span, target) ,
245
247
[ sym:: link, ..] => self . check_link ( hir_id, attr, span, target) ,
246
248
[ sym:: link_name, ..] => self . check_link_name ( hir_id, attr, span, target) ,
247
249
[ sym:: link_section, ..] => self . check_link_section ( hir_id, attr, span, target) ,
@@ -646,8 +648,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
646
648
sym:: instruction_set,
647
649
sym:: repr,
648
650
sym:: rustc_std_internal_symbol,
649
- // code generation
650
- sym:: cold,
651
651
// documentation
652
652
sym:: doc,
653
653
] ;
@@ -681,7 +681,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
681
681
// this check can be part of the parser and be removed here
682
682
match other_attr {
683
683
Attribute :: Parsed (
684
- AttributeKind :: Deprecation { .. } | AttributeKind :: Repr { .. } ,
684
+ AttributeKind :: Deprecation { .. }
685
+ | AttributeKind :: Repr { .. }
686
+ | AttributeKind :: Cold ( ..) ,
685
687
) => {
686
688
continue ;
687
689
}
@@ -1630,23 +1632,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
1630
1632
}
1631
1633
1632
1634
/// Checks if `#[cold]` is applied to a non-function.
1633
- fn check_cold ( & self , hir_id : HirId , attr : & Attribute , span : Span , target : Target ) {
1635
+ fn check_cold ( & self , hir_id : HirId , attr_span : Span , span : Span , target : Target ) {
1634
1636
match target {
1635
1637
Target :: Fn | Target :: Method ( ..) | Target :: ForeignFn | Target :: Closure => { }
1636
1638
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
1637
1639
// `#[cold]` attribute with just a lint, because we previously
1638
1640
// erroneously allowed it and some crates used it accidentally, to be compatible
1639
1641
// with crates depending on them, we can't throw an error here.
1640
1642
Target :: Field | Target :: Arm | Target :: MacroDef => {
1641
- self . inline_attr_str_error_with_macro_def ( hir_id, attr . span ( ) , "cold" ) ;
1643
+ self . inline_attr_str_error_with_macro_def ( hir_id, attr_span , "cold" ) ;
1642
1644
}
1643
1645
_ => {
1644
1646
// FIXME: #[cold] was previously allowed on non-functions and some crates used
1645
1647
// this, so only emit a warning.
1646
1648
self . tcx . emit_node_span_lint (
1647
1649
UNUSED_ATTRIBUTES ,
1648
1650
hir_id,
1649
- attr . span ( ) ,
1651
+ attr_span ,
1650
1652
errors:: Cold { span, on_crate : hir_id == CRATE_HIR_ID } ,
1651
1653
) ;
1652
1654
}
0 commit comments