@@ -89,6 +89,8 @@ impl CheckAttrVisitor<'tcx> {
8989 self . check_allow_internal_unstable ( & attr, span, target, & attrs)
9090 } else if self . tcx . sess . check_name ( attr, sym:: rustc_allow_const_fn_unstable) {
9191 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)
9294 } else {
9395 // lint-only checks
9496 if self . tcx . sess . check_name ( attr, sym:: cold) {
@@ -162,6 +164,25 @@ impl CheckAttrVisitor<'tcx> {
162164 }
163165 }
164166
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+
165186 /// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
166187 fn check_track_caller (
167188 & self ,
@@ -171,7 +192,7 @@ impl CheckAttrVisitor<'tcx> {
171192 target : Target ,
172193 ) -> bool {
173194 match target {
174- _ if self . tcx . sess . contains_name ( attrs , sym:: naked) => {
195+ _ if attrs . iter ( ) . any ( |attr| attr . has_name ( sym:: naked) ) => {
175196 struct_span_err ! (
176197 self . tcx. sess,
177198 * attr_span,
0 commit comments