@@ -155,7 +155,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
155155 [ sym:: rustc_std_internal_symbol] => {
156156 self . check_rustc_std_internal_symbol ( attr, span, target)
157157 }
158- [ sym:: naked] => self . check_naked ( hir_id, attr, span, target) ,
158+ [ sym:: naked] => self . check_naked ( hir_id, attr, span, target, attrs ) ,
159159 [ sym:: rustc_never_returns_null_ptr] => {
160160 self . check_applied_to_fn_or_method ( hir_id, attr, span, target)
161161 }
@@ -410,12 +410,33 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
410410 }
411411
412412 /// 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+
414435 match target {
415436 Target :: Fn
416437 | Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => true ,
417438 // 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
419440 // erroneously allowed it and some crates used it accidentally, to be compatible
420441 // with crates depending on them, we can't throw an error here.
421442 Target :: Field | Target :: Arm | Target :: MacroDef => {
@@ -488,7 +509,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
488509 }
489510 }
490511
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.
492513 fn check_track_caller (
493514 & self ,
494515 hir_id : HirId ,
@@ -498,10 +519,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
498519 target : Target ,
499520 ) -> bool {
500521 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- }
505522 Target :: Fn => {
506523 // `#[track_caller]` is not valid on weak lang items because they are called via
507524 // `extern` declarations and `#[track_caller]` would alter their ABI.
0 commit comments