@@ -80,51 +80,49 @@ impl CheckAttrVisitor<'_> {
8080 self . check_rustc_must_implement_one_of ( attr, span, target)
8181 }
8282 sym:: target_feature => self . check_target_feature ( hir_id, attr, span, target) ,
83- sym:: track_caller => {
84- self . check_track_caller ( hir_id, attr. span , attrs, span, target)
85- }
83+ sym:: track_caller => self . check_track_caller ( hir_id, attr, span, target) ,
8684 sym:: doc => self . check_doc_attrs (
8785 attr,
8886 hir_id,
8987 target,
9088 & mut specified_inline,
9189 & mut doc_aliases,
9290 ) ,
93- sym:: no_link => self . check_no_link ( hir_id, & attr, span, target) ,
94- sym:: export_name => self . check_export_name ( hir_id, & attr, span, target) ,
91+ sym:: no_link => self . check_no_link ( hir_id, attr, span, target) ,
92+ sym:: export_name => self . check_export_name ( hir_id, attr, span, target) ,
9593 sym:: rustc_layout_scalar_valid_range_start
9694 | sym:: rustc_layout_scalar_valid_range_end => {
97- self . check_rustc_layout_scalar_valid_range ( & attr, span, target)
95+ self . check_rustc_layout_scalar_valid_range ( attr, span, target)
9896 }
9997 sym:: allow_internal_unstable => {
100- self . check_allow_internal_unstable ( hir_id, & attr, span, target, & attrs)
98+ self . check_allow_internal_unstable ( hir_id, attr, span, target, attrs)
10199 }
102100 sym:: rustc_allow_const_fn_unstable => {
103- self . check_rustc_allow_const_fn_unstable ( hir_id, & attr, span, target)
101+ self . check_rustc_allow_const_fn_unstable ( hir_id, attr, span, target)
104102 }
105- sym:: naked => self . check_naked ( hir_id, attr, span, target) ,
103+ sym:: naked => self . check_naked ( hir_id, attr, span, target, attrs ) ,
106104 sym:: rustc_legacy_const_generics => {
107- self . check_rustc_legacy_const_generics ( & attr, span, target, item)
105+ self . check_rustc_legacy_const_generics ( attr, span, target, item)
108106 }
109107 sym:: rustc_lint_query_instability => {
110- self . check_rustc_lint_query_instability ( & attr, span, target)
108+ self . check_rustc_lint_query_instability ( attr, span, target)
111109 }
112110 sym:: rustc_clean
113111 | sym:: rustc_dirty
114112 | sym:: rustc_if_this_changed
115- | sym:: rustc_then_this_would_need => self . check_rustc_dirty_clean ( & attr) ,
113+ | sym:: rustc_then_this_would_need => self . check_rustc_dirty_clean ( attr) ,
116114 sym:: cmse_nonsecure_entry => self . check_cmse_nonsecure_entry ( attr, span, target) ,
117115 sym:: default_method_body_is_const => {
118116 self . check_default_method_body_is_const ( attr, span, target)
119117 }
120- sym:: must_not_suspend => self . check_must_not_suspend ( & attr, span, target) ,
121- sym:: must_use => self . check_must_use ( hir_id, & attr, span, target) ,
122- sym:: rustc_pass_by_value => self . check_pass_by_value ( & attr, span, target) ,
118+ sym:: must_not_suspend => self . check_must_not_suspend ( attr, span, target) ,
119+ sym:: must_use => self . check_must_use ( hir_id, attr, span, target) ,
120+ sym:: rustc_pass_by_value => self . check_pass_by_value ( attr, span, target) ,
123121 sym:: rustc_const_unstable
124122 | sym:: rustc_const_stable
125123 | sym:: unstable
126124 | sym:: stable
127- | sym:: rustc_promotable => self . check_stability_promotable ( & attr, span, target) ,
125+ | sym:: rustc_promotable => self . check_stability_promotable ( attr, span, target) ,
128126 _ => true ,
129127 } ;
130128 is_valid &= attr_is_valid;
@@ -338,7 +336,27 @@ impl CheckAttrVisitor<'_> {
338336 }
339337
340338 /// Checks if `#[naked]` is applied to a function definition.
341- fn check_naked ( & self , hir_id : HirId , attr : & Attribute , span : Span , target : Target ) -> bool {
339+ fn check_naked (
340+ & self ,
341+ hir_id : HirId ,
342+ attr : & Attribute ,
343+ span : Span ,
344+ target : Target ,
345+ attrs : & [ Attribute ] ,
346+ ) -> bool {
347+ for any_attr in attrs {
348+ if any_attr. has_name ( sym:: track_caller) || any_attr. has_name ( sym:: inline) {
349+ struct_span_err ! (
350+ self . tcx. sess,
351+ any_attr. span,
352+ E0736 ,
353+ "cannot use additional code generation attributes with `#[naked]`" ,
354+ )
355+ . emit ( ) ;
356+ return false ;
357+ }
358+ }
359+
342360 match target {
343361 Target :: Fn
344362 | Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => true ,
@@ -383,41 +401,28 @@ impl CheckAttrVisitor<'_> {
383401 }
384402 }
385403
386- /// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
404+ /// Checks if a `#[track_caller]` is applied to a function. Returns `true` if valid.
387405 fn check_track_caller (
388406 & self ,
389407 hir_id : HirId ,
390- attr_span : Span ,
391- attrs : & [ Attribute ] ,
408+ attr : & Attribute ,
392409 span : Span ,
393410 target : Target ,
394411 ) -> bool {
395412 match target {
396- _ if attrs. iter ( ) . any ( |attr| attr. has_name ( sym:: naked) ) => {
397- struct_span_err ! (
398- self . tcx. sess,
399- attr_span,
400- E0736 ,
401- "cannot use `#[track_caller]` with `#[naked]`" ,
402- )
403- . emit ( ) ;
404- false
405- }
406413 Target :: Fn | Target :: Method ( ..) | Target :: ForeignFn | Target :: Closure => true ,
407414 // FIXME(#80564): We permit struct fields, match arms and macro defs to have an
408415 // `#[track_caller]` attribute with just a lint, because we previously
409416 // erroneously allowed it and some crates used it accidentally, to to be compatible
410417 // with crates depending on them, we can't throw an error here.
411418 Target :: Field | Target :: Arm | Target :: MacroDef => {
412- for attr in attrs {
413- self . inline_attr_str_error_with_macro_def ( hir_id, attr, "track_caller" ) ;
414- }
419+ self . inline_attr_str_error_with_macro_def ( hir_id, attr, "track_caller" ) ;
415420 true
416421 }
417422 _ => {
418423 struct_span_err ! (
419424 self . tcx. sess,
420- attr_span ,
425+ attr . span ,
421426 E0739 ,
422427 "attribute should be applied to function"
423428 )
0 commit comments