@@ -149,10 +149,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
149149 }
150150 Attribute :: Parsed ( AttributeKind :: Repr ( _) ) => { /* handled below this loop and elsewhere */
151151 }
152+ Attribute :: Parsed ( AttributeKind :: Cold ( attr_span) ) => {
153+ self . check_cold ( hir_id, * attr_span, span, target)
154+ }
152155 Attribute :: Parsed ( AttributeKind :: Align { align, span : repr_span } ) => {
153156 self . check_align ( span, target, * align, * repr_span)
154157 }
155-
156158 Attribute :: Parsed (
157159 AttributeKind :: BodyStability { .. }
158160 | AttributeKind :: ConstStabilityIndirect
@@ -245,7 +247,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
245247 [ sym:: ffi_pure, ..] => self . check_ffi_pure ( attr. span ( ) , attrs, target) ,
246248 [ sym:: ffi_const, ..] => self . check_ffi_const ( attr. span ( ) , target) ,
247249 [ sym:: link_ordinal, ..] => self . check_link_ordinal ( attr, span, target) ,
248- [ sym:: cold, ..] => self . check_cold ( hir_id, attr, span, target) ,
249250 [ sym:: link, ..] => self . check_link ( hir_id, attr, span, target) ,
250251 [ sym:: link_name, ..] => self . check_link_name ( hir_id, attr, span, target) ,
251252 [ sym:: link_section, ..] => self . check_link_section ( hir_id, attr, span, target) ,
@@ -651,8 +652,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
651652 sym:: repr,
652653 sym:: align,
653654 sym:: rustc_std_internal_symbol,
654- // code generation
655- sym:: cold,
656655 // documentation
657656 sym:: doc,
658657 ] ;
@@ -688,7 +687,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
688687 Attribute :: Parsed (
689688 AttributeKind :: Deprecation { .. }
690689 | AttributeKind :: Repr { .. }
691- | AttributeKind :: Align { .. } ,
690+ | AttributeKind :: Align { .. }
691+ | AttributeKind :: Cold ( ..) ,
692692 ) => {
693693 continue ;
694694 }
@@ -1637,23 +1637,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
16371637 }
16381638
16391639 /// Checks if `#[cold]` is applied to a non-function.
1640- fn check_cold ( & self , hir_id : HirId , attr : & Attribute , span : Span , target : Target ) {
1640+ fn check_cold ( & self , hir_id : HirId , attr_span : Span , span : Span , target : Target ) {
16411641 match target {
16421642 Target :: Fn | Target :: Method ( ..) | Target :: ForeignFn | Target :: Closure => { }
16431643 // FIXME(#80564): We permit struct fields, match arms and macro defs to have an
16441644 // `#[cold]` attribute with just a lint, because we previously
16451645 // erroneously allowed it and some crates used it accidentally, to be compatible
16461646 // with crates depending on them, we can't throw an error here.
16471647 Target :: Field | Target :: Arm | Target :: MacroDef => {
1648- self . inline_attr_str_error_with_macro_def ( hir_id, attr . span ( ) , "cold" ) ;
1648+ self . inline_attr_str_error_with_macro_def ( hir_id, attr_span , "cold" ) ;
16491649 }
16501650 _ => {
16511651 // FIXME: #[cold] was previously allowed on non-functions and some crates used
16521652 // this, so only emit a warning.
16531653 self . tcx . emit_node_span_lint (
16541654 UNUSED_ATTRIBUTES ,
16551655 hir_id,
1656- attr . span ( ) ,
1656+ attr_span ,
16571657 errors:: Cold { span, on_crate : hir_id == CRATE_HIR_ID } ,
16581658 ) ;
16591659 }
0 commit comments