Skip to content

Commit dc8403f

Browse files
committed
inline_fn_without_body: inline into a single function
1 parent 8e2ddc8 commit dc8403f

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

clippy_lints/src/inline_fn_without_body.rs

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::sugg::DiagExt;
5-
use rustc_ast::ast::Attribute;
65
use rustc_errors::Applicability;
76
use rustc_hir::{TraitFn, TraitItem, TraitItemKind};
87
use rustc_lint::{LateContext, LateLintPass};
98
use rustc_session::declare_lint_pass;
10-
use rustc_span::{sym, Symbol};
9+
use rustc_span::sym;
1110

1211
declare_clippy_lint! {
1312
/// ### What it does
@@ -34,27 +33,23 @@ declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
3433

3534
impl<'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

Comments
 (0)