1
- use clippy_utils:: diagnostics:: span_lint;
1
+ use clippy_utils:: diagnostics:: { span_lint, span_lint_hir } ;
2
2
use rustc_hir:: attrs:: AttributeKind ;
3
3
use rustc_hir:: def_id:: DefId ;
4
4
use rustc_hir:: { self as hir, Attribute , find_attr} ;
@@ -64,14 +64,20 @@ declare_clippy_lint! {
64
64
"detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)"
65
65
}
66
66
67
- fn check_missing_inline_attrs ( cx : & LateContext < ' _ > , attrs : & [ Attribute ] , sp : Span , desc : & ' static str ) {
67
+ fn check_missing_inline_attrs (
68
+ cx : & LateContext < ' _ > ,
69
+ attrs : & [ Attribute ] ,
70
+ sp : Span ,
71
+ desc : & ' static str ,
72
+ hir_id : Option < hir:: HirId > ,
73
+ ) {
68
74
if !find_attr ! ( attrs, AttributeKind :: Inline ( ..) ) {
69
- span_lint (
70
- cx ,
71
- MISSING_INLINE_IN_PUBLIC_ITEMS ,
72
- sp ,
73
- format ! ( "missing `#[inline]` for {desc}" ) ,
74
- ) ;
75
+ let msg = format ! ( "missing `#[inline]` for {desc}" ) ;
76
+ if let Some ( hir_id ) = hir_id {
77
+ span_lint_hir ( cx , MISSING_INLINE_IN_PUBLIC_ITEMS , hir_id , sp , msg ) ;
78
+ } else {
79
+ span_lint ( cx , MISSING_INLINE_IN_PUBLIC_ITEMS , sp , msg ) ;
80
+ }
75
81
}
76
82
}
77
83
@@ -103,17 +109,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
103
109
104
110
let desc = "a function" ;
105
111
let attrs = cx. tcx . hir_attrs ( it. hir_id ( ) ) ;
106
- check_missing_inline_attrs ( cx, attrs, it. span , desc) ;
112
+ check_missing_inline_attrs ( cx, attrs, it. span , desc, None ) ;
107
113
} ,
108
- hir:: ItemKind :: Trait (
109
- ref _constness,
110
- ref _is_auto,
111
- ref _unsafe,
112
- _ident,
113
- _generics,
114
- _bounds,
115
- trait_items,
116
- ) => {
114
+ hir:: ItemKind :: Trait ( .., trait_items) => {
117
115
// note: we need to check if the trait is exported so we can't use
118
116
// `LateLintPass::check_trait_item` here.
119
117
for & tit in trait_items {
@@ -127,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
127
125
let desc = "a default trait method" ;
128
126
let item = cx. tcx . hir_trait_item ( tit) ;
129
127
let attrs = cx. tcx . hir_attrs ( item. hir_id ( ) ) ;
130
- check_missing_inline_attrs ( cx, attrs, item. span , desc) ;
128
+ check_missing_inline_attrs ( cx, attrs, item. span , desc, Some ( tit . hir_id ( ) ) ) ;
131
129
}
132
130
} ,
133
131
}
@@ -182,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
182
180
}
183
181
184
182
let attrs = cx. tcx . hir_attrs ( impl_item. hir_id ( ) ) ;
185
- check_missing_inline_attrs ( cx, attrs, impl_item. span , desc) ;
183
+ check_missing_inline_attrs ( cx, attrs, impl_item. span , desc, None ) ;
186
184
}
187
185
}
188
186
0 commit comments