22
33use clippy_utils:: diagnostics:: span_lint_and_then;
44use clippy_utils:: sugg:: DiagExt ;
5- use rustc_ast:: ast:: Attribute ;
65use rustc_errors:: Applicability ;
76use rustc_hir:: { TraitFn , TraitItem , TraitItemKind } ;
87use rustc_lint:: { LateContext , LateLintPass } ;
98use rustc_session:: declare_lint_pass;
10- use rustc_span:: { sym, Symbol } ;
9+ use rustc_span:: sym;
1110
1211declare_clippy_lint ! {
1312 /// ### What it does
@@ -34,27 +33,23 @@ declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
3433
3534impl < ' tcx > LateLintPass < ' tcx > for InlineFnWithoutBody {
3635 fn check_trait_item ( & mut self , cx : & LateContext < ' tcx > , item : & ' tcx TraitItem < ' _ > ) {
37- if let TraitItemKind :: Fn ( _, TraitFn :: Required ( _) ) = item. kind {
38- let attrs = cx. tcx . hir ( ) . attrs ( item. hir_id ( ) ) ;
39- check_attrs ( cx, item. ident . name , attrs) ;
36+ if let TraitItemKind :: Fn ( _, TraitFn :: Required ( _) ) = item. kind
37+ && let Some ( attr) = cx
38+ . tcx
39+ . hir ( )
40+ . attrs ( item. hir_id ( ) )
41+ . iter ( )
42+ . find ( |a| a. has_name ( sym:: inline) )
43+ {
44+ span_lint_and_then (
45+ cx,
46+ INLINE_FN_WITHOUT_BODY ,
47+ attr. span ,
48+ format ! ( "use of `#[inline]` on trait method `{}` which has no body" , item. ident) ,
49+ |diag| {
50+ diag. suggest_remove_item ( cx, attr. span , "remove" , Applicability :: MachineApplicable ) ;
51+ } ,
52+ ) ;
4053 }
4154 }
4255}
43-
44- fn check_attrs ( cx : & LateContext < ' _ > , name : Symbol , attrs : & [ Attribute ] ) {
45- for attr in attrs {
46- if !attr. has_name ( sym:: inline) {
47- continue ;
48- }
49-
50- span_lint_and_then (
51- cx,
52- INLINE_FN_WITHOUT_BODY ,
53- attr. span ,
54- format ! ( "use of `#[inline]` on trait method `{name}` which has no body" ) ,
55- |diag| {
56- diag. suggest_remove_item ( cx, attr. span , "remove" , Applicability :: MachineApplicable ) ;
57- } ,
58- ) ;
59- }
60- }
0 commit comments