@@ -8,6 +8,7 @@ use crate::hir::{self, HirId, HirVec, Attribute, Item, ItemKind, TraitItem, Trai
88use crate :: hir:: DUMMY_HIR_ID ;
99use crate :: hir:: def_id:: DefId ;
1010use crate :: hir:: intravisit:: { self , Visitor , NestedVisitorMap } ;
11+ use crate :: lint:: builtin:: UNUSED_ATTRIBUTES ;
1112use crate :: ty:: TyCtxt ;
1213use crate :: ty:: query:: Providers ;
1314
@@ -36,6 +37,9 @@ pub(crate) enum Target {
3637 Impl ,
3738 Expression ,
3839 Statement ,
40+ AssocConst ,
41+ Method { body : bool } ,
42+ AssocTy ,
3943}
4044
4145impl Display for Target {
@@ -60,6 +64,9 @@ impl Display for Target {
6064 Target :: Impl => "item" ,
6165 Target :: Expression => "expression" ,
6266 Target :: Statement => "statement" ,
67+ Target :: AssocConst => "associated const" ,
68+ Target :: Method { .. } => "method" ,
69+ Target :: AssocTy => "associated type" ,
6370 } )
6471 }
6572}
@@ -85,6 +92,19 @@ impl Target {
8592 ItemKind :: Impl ( ..) => Target :: Impl ,
8693 }
8794 }
95+
96+ fn from_trait_item ( trait_item : & TraitItem ) -> Target {
97+ match trait_item. kind {
98+ TraitItemKind :: Const ( ..) => Target :: AssocConst ,
99+ TraitItemKind :: Method ( _, hir:: TraitMethod :: Required ( _) ) => {
100+ Target :: Method { body : false }
101+ }
102+ TraitItemKind :: Method ( _, hir:: TraitMethod :: Provided ( _) ) => {
103+ Target :: Method { body : true }
104+ }
105+ TraitItemKind :: Type ( ..) => Target :: AssocTy ,
106+ }
107+ }
88108 }
89109 }
90110}
@@ -136,6 +156,15 @@ impl CheckAttrVisitor<'tcx> {
136156 fn check_inline ( & self , hir_id : HirId , attr : & Attribute , span : & Span , target : Target ) -> bool {
137157 match target {
138158 Target :: Fn | Target :: Closure | Target :: Method { body : true } => true ,
159+ Target :: Method { body : false } | Target :: ForeignFn => {
160+ self . tcx . struct_span_lint_hir (
161+ UNUSED_ATTRIBUTES ,
162+ hir_id,
163+ attr. span ,
164+ "`#[inline]` is ignored on function prototypes" ,
165+ ) . emit ( ) ;
166+ true
167+ }
139168 _ => {
140169 struct_span_err ! ( self . tcx. sess,
141170 attr. span,
@@ -392,6 +421,11 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
392421 intravisit:: walk_item ( self , item)
393422 }
394423
424+ fn visit_trait_item ( & mut self , trait_item : & ' tcx TraitItem ) {
425+ let target = Target :: from_trait_item ( trait_item) ;
426+ self . check_attributes ( trait_item. hir_id , & trait_item. attrs , & trait_item. span , target, None ) ;
427+ intravisit:: walk_trait_item ( self , trait_item)
428+ }
395429
396430 fn visit_stmt ( & mut self , stmt : & ' tcx hir:: Stmt ) {
397431 self . check_stmt_attributes ( stmt) ;
0 commit comments