2
2
3
3
use clippy_utils:: diagnostics:: span_lint_and_then;
4
4
use clippy_utils:: sugg:: DiagExt ;
5
- use rustc_ast:: ast:: Attribute ;
6
5
use rustc_errors:: Applicability ;
7
6
use rustc_hir:: { TraitFn , TraitItem , TraitItemKind } ;
8
7
use rustc_lint:: { LateContext , LateLintPass } ;
9
8
use rustc_session:: declare_lint_pass;
10
- use rustc_span:: { sym, Symbol } ;
9
+ use rustc_span:: sym;
11
10
12
11
declare_clippy_lint ! {
13
12
/// ### What it does
@@ -34,27 +33,23 @@ declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
34
33
35
34
impl < ' tcx > LateLintPass < ' tcx > for InlineFnWithoutBody {
36
35
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
+ ) ;
40
53
}
41
54
}
42
55
}
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