@@ -89,6 +89,8 @@ impl CheckAttrVisitor<'tcx> {
89
89
self . check_allow_internal_unstable ( & attr, span, target, & attrs)
90
90
} else if self . tcx . sess . check_name ( attr, sym:: rustc_allow_const_fn_unstable) {
91
91
self . check_rustc_allow_const_fn_unstable ( hir_id, & attr, span, target)
92
+ } else if self . tcx . sess . check_name ( attr, sym:: naked) {
93
+ self . check_naked ( attr, span, target)
92
94
} else {
93
95
// lint-only checks
94
96
if self . tcx . sess . check_name ( attr, sym:: cold) {
@@ -162,6 +164,25 @@ impl CheckAttrVisitor<'tcx> {
162
164
}
163
165
}
164
166
167
+ /// Checks if `#[naked]` is applied to a function definition.
168
+ fn check_naked ( & self , attr : & Attribute , span : & Span , target : Target ) -> bool {
169
+ match target {
170
+ Target :: Fn
171
+ | Target :: Method ( MethodKind :: Trait { body : true } | MethodKind :: Inherent ) => true ,
172
+ _ => {
173
+ self . tcx
174
+ . sess
175
+ . struct_span_err (
176
+ attr. span ,
177
+ "attribute should be applied to a function definition" ,
178
+ )
179
+ . span_label ( * span, "not a function definition" )
180
+ . emit ( ) ;
181
+ false
182
+ }
183
+ }
184
+ }
185
+
165
186
/// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
166
187
fn check_track_caller (
167
188
& self ,
@@ -171,7 +192,7 @@ impl CheckAttrVisitor<'tcx> {
171
192
target : Target ,
172
193
) -> bool {
173
194
match target {
174
- _ if self . tcx . sess . contains_name ( attrs , sym:: naked) => {
195
+ _ if attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: naked) ) => {
175
196
struct_span_err ! (
176
197
self . tcx. sess,
177
198
* attr_span,
0 commit comments