1- use clippy_utils:: diagnostics:: span_lint;
1+ use clippy_utils:: diagnostics:: { span_lint, span_lint_hir } ;
22use rustc_hir:: attrs:: AttributeKind ;
33use rustc_hir:: def_id:: DefId ;
44use rustc_hir:: { self as hir, Attribute , find_attr} ;
@@ -64,14 +64,20 @@ declare_clippy_lint! {
6464 "detects missing `#[inline]` attribute for public callables (functions, trait methods, methods...)"
6565}
6666
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+ ) {
6874 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+ }
7581 }
7682}
7783
@@ -103,17 +109,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
103109
104110 let desc = "a function" ;
105111 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 ) ;
107113 } ,
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) => {
117115 // note: we need to check if the trait is exported so we can't use
118116 // `LateLintPass::check_trait_item` here.
119117 for & tit in trait_items {
@@ -127,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
127125 let desc = "a default trait method" ;
128126 let item = cx. tcx . hir_trait_item ( tit) ;
129127 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 ( ) ) ) ;
131129 }
132130 } ,
133131 }
@@ -182,7 +180,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
182180 }
183181
184182 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 ) ;
186184 }
187185}
188186
0 commit comments