@@ -11,7 +11,7 @@ use crate::ty::TyCtxt;
11
11
use crate :: ty:: query:: Providers ;
12
12
13
13
use std:: fmt:: { self , Display } ;
14
- use syntax:: symbol:: sym;
14
+ use syntax:: { attr , symbol:: sym} ;
15
15
use syntax_pos:: Span ;
16
16
17
17
#[ derive( Copy , Clone , PartialEq ) ]
@@ -94,7 +94,6 @@ impl CheckAttrVisitor<'tcx> {
94
94
/// Checks any attribute.
95
95
fn check_attributes ( & self , item : & hir:: Item , target : Target ) {
96
96
let mut is_valid = true ;
97
- let mut track_caller_span = None ;
98
97
for attr in & item. attrs {
99
98
is_valid &= if attr. check_name ( sym:: inline) {
100
99
self . check_inline ( attr, & item. span , target)
@@ -105,7 +104,6 @@ impl CheckAttrVisitor<'tcx> {
105
104
} else if attr. check_name ( sym:: target_feature) {
106
105
self . check_target_feature ( attr, item, target)
107
106
} else if attr. check_name ( sym:: track_caller) {
108
- track_caller_span = Some ( attr. span ) ;
109
107
self . check_track_caller ( attr, & item, target)
110
108
} else {
111
109
true
@@ -122,19 +120,6 @@ impl CheckAttrVisitor<'tcx> {
122
120
123
121
self . check_repr ( item, target) ;
124
122
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
- }
138
123
}
139
124
140
125
/// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
@@ -152,7 +137,7 @@ impl CheckAttrVisitor<'tcx> {
152
137
}
153
138
}
154
139
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 .
156
141
fn check_track_caller ( & self , attr : & hir:: Attribute , item : & hir:: Item , target : Target ) -> bool {
157
142
if target != Target :: Fn {
158
143
struct_span_err ! (
@@ -164,6 +149,15 @@ impl CheckAttrVisitor<'tcx> {
164
149
. span_label ( item. span , "not a function" )
165
150
. emit ( ) ;
166
151
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
167
161
} else {
168
162
true
169
163
}
0 commit comments