@@ -119,13 +119,13 @@ impl CheckAttrVisitor<'_> {
119
119
}
120
120
sym:: naked => self . check_naked ( hir_id, attr, span, target) ,
121
121
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)
123
123
}
124
124
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)
126
126
}
127
127
sym:: rustc_lint_diagnostics => {
128
- self . check_rustc_lint_diagnostics ( & attr, span, target)
128
+ self . check_rustc_lint_diagnostics ( hir_id , & attr, span, target)
129
129
}
130
130
sym:: rustc_lint_opt_ty => self . check_rustc_lint_opt_ty ( & attr, span, target) ,
131
131
sym:: rustc_lint_opt_deny_field_access => {
@@ -135,7 +135,9 @@ impl CheckAttrVisitor<'_> {
135
135
| sym:: rustc_dirty
136
136
| sym:: rustc_if_this_changed
137
137
| 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
+ }
139
141
sym:: collapse_debuginfo => self . check_collapse_debuginfo ( attr, span, target) ,
140
142
sym:: const_trait => self . check_const_trait ( attr, span, target) ,
141
143
sym:: must_not_suspend => self . check_must_not_suspend ( & attr, span, target) ,
@@ -386,21 +388,29 @@ impl CheckAttrVisitor<'_> {
386
388
self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
387
389
attr_span : attr. span ,
388
390
defn_span : span,
391
+ on_crate : hir_id == CRATE_HIR_ID ,
389
392
} ) ;
390
393
false
391
394
}
392
395
}
393
396
}
394
397
395
398
/// 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 {
397
406
match target {
398
407
Target :: Fn
399
408
| Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => true ,
400
409
_ => {
401
410
self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
402
411
attr_span : attr. span ,
403
412
defn_span : span,
413
+ on_crate : hir_id == CRATE_HIR_ID ,
404
414
} ) ;
405
415
false
406
416
}
@@ -465,9 +475,11 @@ impl CheckAttrVisitor<'_> {
465
475
true
466
476
}
467
477
_ => {
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
+ } ) ;
471
483
false
472
484
}
473
485
}
@@ -576,6 +588,7 @@ impl CheckAttrVisitor<'_> {
576
588
self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
577
589
attr_span : attr. span ,
578
590
defn_span : span,
591
+ on_crate : hir_id == CRATE_HIR_ID ,
579
592
} ) ;
580
593
false
581
594
}
@@ -1240,7 +1253,7 @@ impl CheckAttrVisitor<'_> {
1240
1253
UNUSED_ATTRIBUTES ,
1241
1254
hir_id,
1242
1255
attr. span ,
1243
- errors:: Cold { span } ,
1256
+ errors:: Cold { span, on_crate : hir_id == CRATE_HIR_ID } ,
1244
1257
) ;
1245
1258
}
1246
1259
}
@@ -1376,6 +1389,7 @@ impl CheckAttrVisitor<'_> {
1376
1389
/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
1377
1390
fn check_rustc_legacy_const_generics (
1378
1391
& self ,
1392
+ hir_id : HirId ,
1379
1393
attr : & Attribute ,
1380
1394
span : Span ,
1381
1395
target : Target ,
@@ -1386,6 +1400,7 @@ impl CheckAttrVisitor<'_> {
1386
1400
self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
1387
1401
attr_span : attr. span ,
1388
1402
defn_span : span,
1403
+ on_crate : hir_id == CRATE_HIR_ID ,
1389
1404
} ) ;
1390
1405
return false ;
1391
1406
}
@@ -1450,12 +1465,19 @@ impl CheckAttrVisitor<'_> {
1450
1465
1451
1466
/// Helper function for checking that the provided attribute is only applied to a function or
1452
1467
/// 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 {
1454
1475
let is_function = matches ! ( target, Target :: Fn | Target :: Method ( ..) ) ;
1455
1476
if !is_function {
1456
1477
self . tcx . sess . emit_err ( errors:: AttrShouldBeAppliedToFn {
1457
1478
attr_span : attr. span ,
1458
1479
defn_span : span,
1480
+ on_crate : hir_id == CRATE_HIR_ID ,
1459
1481
} ) ;
1460
1482
false
1461
1483
} else {
@@ -1467,17 +1489,24 @@ impl CheckAttrVisitor<'_> {
1467
1489
/// or method.
1468
1490
fn check_rustc_lint_query_instability (
1469
1491
& self ,
1492
+ hir_id : HirId ,
1470
1493
attr : & Attribute ,
1471
1494
span : Span ,
1472
1495
target : Target ,
1473
1496
) -> 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)
1475
1498
}
1476
1499
1477
1500
/// Checks that the `#[rustc_lint_diagnostics]` attribute is only applied to a function or
1478
1501
/// 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)
1481
1510
}
1482
1511
1483
1512
/// Checks that the `#[rustc_lint_opt_ty]` attribute is only applied to a struct.
0 commit comments