@@ -11,7 +11,7 @@ use crate::ty::TyCtxt;
1111use crate :: ty:: query:: Providers ;
1212
1313use std:: fmt:: { self , Display } ;
14- use syntax:: symbol:: sym;
14+ use syntax:: { attr , symbol:: sym} ;
1515use syntax_pos:: Span ;
1616
1717#[ derive( Copy , Clone , PartialEq ) ]
@@ -94,7 +94,6 @@ impl CheckAttrVisitor<'tcx> {
9494 /// Checks any attribute.
9595 fn check_attributes ( & self , item : & hir:: Item , target : Target ) {
9696 let mut is_valid = true ;
97- let mut track_caller_span = None ;
9897 for attr in & item. attrs {
9998 is_valid &= if attr. check_name ( sym:: inline) {
10099 self . check_inline ( attr, & item. span , target)
@@ -105,7 +104,6 @@ impl CheckAttrVisitor<'tcx> {
105104 } else if attr. check_name ( sym:: target_feature) {
106105 self . check_target_feature ( attr, item, target)
107106 } else if attr. check_name ( sym:: track_caller) {
108- track_caller_span = Some ( attr. span ) ;
109107 self . check_track_caller ( attr, & item, target)
110108 } else {
111109 true
@@ -122,19 +120,6 @@ impl CheckAttrVisitor<'tcx> {
122120
123121 self . check_repr ( item, target) ;
124122 self . check_used ( item, target) ;
125-
126- // Checks if `#[track_caller]` and `#[naked]` are both used.
127- if let Some ( span) = track_caller_span {
128- if item. attrs . iter ( ) . any ( |attr| attr. check_name ( sym:: naked) ) {
129- struct_span_err ! (
130- self . tcx. sess,
131- span,
132- E0901 ,
133- "cannot use `#[track_caller]` with `#[naked]`" ,
134- )
135- . emit ( ) ;
136- }
137- }
138123 }
139124
140125 /// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
@@ -152,7 +137,7 @@ impl CheckAttrVisitor<'tcx> {
152137 }
153138 }
154139
155- /// Checks if a `#[target_feature ]` can be applied.
140+ /// Checks if a `#[track_caller ]` is applied to a non-naked function. Returns `true` if valid .
156141 fn check_track_caller ( & self , attr : & hir:: Attribute , item : & hir:: Item , target : Target ) -> bool {
157142 if target != Target :: Fn {
158143 struct_span_err ! (
@@ -164,6 +149,15 @@ impl CheckAttrVisitor<'tcx> {
164149 . span_label ( item. span , "not a function" )
165150 . emit ( ) ;
166151 false
152+ } else if attr:: contains_name ( & item. attrs , sym:: naked) {
153+ struct_span_err ! (
154+ self . tcx. sess,
155+ attr. span,
156+ E0901 ,
157+ "cannot use `#[track_caller]` with `#[naked]`" ,
158+ )
159+ . emit ( ) ;
160+ false
167161 } else {
168162 true
169163 }
0 commit comments