@@ -155,7 +155,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
155
155
[ sym:: rustc_std_internal_symbol] => {
156
156
self . check_rustc_std_internal_symbol ( attr, span, target)
157
157
}
158
- [ sym:: naked] => self . check_naked ( hir_id, attr, span, target) ,
158
+ [ sym:: naked] => self . check_naked ( hir_id, attr, span, target, attrs ) ,
159
159
[ sym:: rustc_never_returns_null_ptr] => {
160
160
self . check_applied_to_fn_or_method ( hir_id, attr, span, target)
161
161
}
@@ -410,12 +410,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
410
410
}
411
411
412
412
/// Checks if `#[naked]` is applied to a function definition.
413
- fn check_naked ( & self , hir_id : HirId , attr : & Attribute , span : Span , target : Target ) -> bool {
413
+ fn check_naked (
414
+ & self ,
415
+ hir_id : HirId ,
416
+ attr : & Attribute ,
417
+ span : Span ,
418
+ target : Target ,
419
+ attrs : & [ Attribute ] ,
420
+ ) -> bool {
421
+ const FORBIDDEN : [ rustc_span:: Symbol ; 3 ] =
422
+ [ sym:: track_caller, sym:: inline, sym:: target_feature] ;
423
+
424
+ for other_attr in attrs {
425
+ if FORBIDDEN . into_iter ( ) . any ( |name| other_attr. has_name ( name) ) {
426
+ self . dcx ( ) . emit_err ( errors:: NakedFunctionCodegenAttribute {
427
+ span : other_attr. span ,
428
+ naked_span : attr. span ,
429
+ } ) ;
430
+
431
+ return false ;
432
+ }
433
+ }
434
+
414
435
match target {
415
436
Target :: Fn
416
437
| Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => true ,
417
438
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
418
- // `#[allow_internal_unstable ]` attribute with just a lint, because we previously
439
+ // `#[naked ]` attribute with just a lint, because we previously
419
440
// erroneously allowed it and some crates used it accidentally, to be compatible
420
441
// with crates depending on them, we can't throw an error here.
421
442
Target :: Field | Target :: Arm | Target :: MacroDef => {
@@ -488,7 +509,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
488
509
}
489
510
}
490
511
491
- /// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
512
+ /// Checks if a `#[track_caller]` is applied to a function. Returns `true` if valid.
492
513
fn check_track_caller (
493
514
& self ,
494
515
hir_id : HirId ,
@@ -498,10 +519,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
498
519
target : Target ,
499
520
) -> bool {
500
521
match target {
501
- _ if attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: naked) ) => {
502
- self . dcx ( ) . emit_err ( errors:: NakedTrackedCaller { attr_span } ) ;
503
- false
504
- }
505
522
Target :: Fn => {
506
523
// `#[track_caller]` is not valid on weak lang items because they are called via
507
524
// `extern` declarations and `#[track_caller]` would alter their ABI.
0 commit comments