@@ -119,13 +119,13 @@ impl CheckAttrVisitor<'_> {
119119 }
120120 sym:: naked => self . check_naked ( hir_id, attr, span, target) ,
121121 sym:: rustc_legacy_const_generics => {
122- self . check_rustc_legacy_const_generics ( & attr, span, target, item)
122+ self . check_rustc_legacy_const_generics ( hir_id , & attr, span, target, item)
123123 }
124124 sym:: rustc_lint_query_instability => {
125- self . check_rustc_lint_query_instability ( & attr, span, target)
125+ self . check_rustc_lint_query_instability ( hir_id , & attr, span, target)
126126 }
127127 sym:: rustc_lint_diagnostics => {
128- self . check_rustc_lint_diagnostics ( & attr, span, target)
128+ self . check_rustc_lint_diagnostics ( hir_id , & attr, span, target)
129129 }
130130 sym:: rustc_lint_opt_ty => self . check_rustc_lint_opt_ty ( & attr, span, target) ,
131131 sym:: rustc_lint_opt_deny_field_access => {
@@ -135,7 +135,9 @@ impl CheckAttrVisitor<'_> {
135135 | sym:: rustc_dirty
136136 | sym:: rustc_if_this_changed
137137 | sym:: rustc_then_this_would_need => self . check_rustc_dirty_clean ( & attr) ,
138- sym:: cmse_nonsecure_entry => self . check_cmse_nonsecure_entry ( attr, span, target) ,
138+ sym:: cmse_nonsecure_entry => {
139+ self . check_cmse_nonsecure_entry ( hir_id, attr, span, target)
140+ }
139141 sym:: collapse_debuginfo => self . check_collapse_debuginfo ( attr, span, target) ,
140142 sym:: const_trait => self . check_const_trait ( attr, span, target) ,
141143 sym:: must_not_suspend => self . check_must_not_suspend ( & attr, span, target) ,
@@ -386,21 +388,29 @@ impl CheckAttrVisitor<'_> {
386388 self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
387389 attr_span : attr. span ,
388390 defn_span : span,
391+ on_crate : hir_id == CRATE_HIR_ID ,
389392 } ) ;
390393 false
391394 }
392395 }
393396 }
394397
395398 /// Checks if `#[cmse_nonsecure_entry]` is applied to a function definition.
396- fn check_cmse_nonsecure_entry ( & self , attr : & Attribute , span : Span , target : Target ) -> bool {
399+ fn check_cmse_nonsecure_entry (
400+ & self ,
401+ hir_id : HirId ,
402+ attr : & Attribute ,
403+ span : Span ,
404+ target : Target ,
405+ ) -> bool {
397406 match target {
398407 Target :: Fn
399408 | Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => true ,
400409 _ => {
401410 self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
402411 attr_span : attr. span ,
403412 defn_span : span,
413+ on_crate : hir_id == CRATE_HIR_ID ,
404414 } ) ;
405415 false
406416 }
@@ -465,9 +475,11 @@ impl CheckAttrVisitor<'_> {
465475 true
466476 }
467477 _ => {
468- self . tcx
469- . sess
470- . emit_err ( errors:: TrackedCallerWrongLocation { attr_span, defn_span : span } ) ;
478+ self . tcx . sess . emit_err ( errors:: TrackedCallerWrongLocation {
479+ attr_span,
480+ defn_span : span,
481+ on_crate : hir_id == CRATE_HIR_ID ,
482+ } ) ;
471483 false
472484 }
473485 }
@@ -576,6 +588,7 @@ impl CheckAttrVisitor<'_> {
576588 self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
577589 attr_span : attr. span ,
578590 defn_span : span,
591+ on_crate : hir_id == CRATE_HIR_ID ,
579592 } ) ;
580593 false
581594 }
@@ -1240,7 +1253,7 @@ impl CheckAttrVisitor<'_> {
12401253 UNUSED_ATTRIBUTES ,
12411254 hir_id,
12421255 attr. span ,
1243- errors:: Cold { span } ,
1256+ errors:: Cold { span, on_crate : hir_id == CRATE_HIR_ID } ,
12441257 ) ;
12451258 }
12461259 }
@@ -1376,6 +1389,7 @@ impl CheckAttrVisitor<'_> {
13761389 /// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
13771390 fn check_rustc_legacy_const_generics (
13781391 & self ,
1392+ hir_id : HirId ,
13791393 attr : & Attribute ,
13801394 span : Span ,
13811395 target : Target ,
@@ -1386,6 +1400,7 @@ impl CheckAttrVisitor<'_> {
13861400 self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
13871401 attr_span : attr. span ,
13881402 defn_span : span,
1403+ on_crate : hir_id == CRATE_HIR_ID ,
13891404 } ) ;
13901405 return false ;
13911406 }
@@ -1450,12 +1465,19 @@ impl CheckAttrVisitor<'_> {
14501465
14511466 /// Helper function for checking that the provided attribute is only applied to a function or
14521467 /// method.
1453- fn check_applied_to_fn_or_method ( & self , attr : & Attribute , span : Span , target : Target ) -> bool {
1468+ fn check_applied_to_fn_or_method (
1469+ & self ,
1470+ hir_id : HirId ,
1471+ attr : & Attribute ,
1472+ span : Span ,
1473+ target : Target ,
1474+ ) -> bool {
14541475 let is_function = matches ! ( target, Target :: Fn | Target :: Method ( ..) ) ;
14551476 if !is_function {
14561477 self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
14571478 attr_span : attr. span ,
14581479 defn_span : span,
1480+ on_crate : hir_id == CRATE_HIR_ID ,
14591481 } ) ;
14601482 false
14611483 } else {
@@ -1467,17 +1489,24 @@ impl CheckAttrVisitor<'_> {
14671489 /// or method.
14681490 fn check_rustc_lint_query_instability (
14691491 & self ,
1492+ hir_id : HirId ,
14701493 attr : & Attribute ,
14711494 span : Span ,
14721495 target : Target ,
14731496 ) -> bool {
1474- self . check_applied_to_fn_or_method ( attr, span, target)
1497+ self . check_applied_to_fn_or_method ( hir_id , attr, span, target)
14751498 }
14761499
14771500 /// Checks that the `#[rustc_lint_diagnostics]` attribute is only applied to a function or
14781501 /// method.
1479- fn check_rustc_lint_diagnostics ( & self , attr : & Attribute , span : Span , target : Target ) -> bool {
1480- self . check_applied_to_fn_or_method ( attr, span, target)
1502+ fn check_rustc_lint_diagnostics (
1503+ & self ,
1504+ hir_id : HirId ,
1505+ attr : & Attribute ,
1506+ span : Span ,
1507+ target : Target ,
1508+ ) -> bool {
1509+ self . check_applied_to_fn_or_method ( hir_id, attr, span, target)
14811510 }
14821511
14831512 /// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
0 commit comments