1 //! checks for `#[inline]` on trait methods without bodies
5 use syntax::ast::{Attribute, Name};
6 use crate::utils::span_lint_and_then;
7 use crate::utils::sugg::DiagnosticBuilderExt;
9 /// **What it does:** Checks for `#[inline]` on trait methods without bodies
11 /// **Why is this bad?** Only implementations of trait methods may be inlined.
12 /// The inline attribute is ignored for trait methods without bodies.
14 /// **Known problems:** None.
20 /// fn name(&self) -> &'static str;
23 declare_clippy_lint! {
24 pub INLINE_FN_WITHOUT_BODY,
26 "use of `#[inline]` on trait methods without bodies"
29 #[derive(Copy, Clone)]
32 impl LintPass for Pass {
33 fn get_lints(&self) -> LintArray {
34 lint_array!(INLINE_FN_WITHOUT_BODY)
38 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
39 fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
40 if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
41 check_attrs(cx, item.name, &item.attrs);
46 fn check_attrs(cx: &LateContext, name: Name, attrs: &[Attribute]) {
48 if attr.name() != "inline" {
54 INLINE_FN_WITHOUT_BODY,
56 &format!("use of `#[inline]` on trait method `{}` which has no body", name),
58 db.suggest_remove_item(cx, attr.span, "remove");