1 //! checks for `#[inline]` on trait methods without bodies
3 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4 use rustc::{declare_tool_lint, lint_array};
6 use syntax::ast::{Attribute, Name};
7 use crate::utils::span_lint_and_then;
8 use crate::utils::sugg::DiagnosticBuilderExt;
10 /// **What it does:** Checks for `#[inline]` on trait methods without bodies
12 /// **Why is this bad?** Only implementations of trait methods may be inlined.
13 /// The inline attribute is ignored for trait methods without bodies.
15 /// **Known problems:** None.
21 /// fn name(&self) -> &'static str;
24 declare_clippy_lint! {
25 pub INLINE_FN_WITHOUT_BODY,
27 "use of `#[inline]` on trait methods without bodies"
30 #[derive(Copy, Clone)]
33 impl LintPass for Pass {
34 fn get_lints(&self) -> LintArray {
35 lint_array!(INLINE_FN_WITHOUT_BODY)
39 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
40 fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
41 if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
42 check_attrs(cx, item.ident.name, &item.attrs);
47 fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) {
49 if attr.name() != "inline" {
55 INLINE_FN_WITHOUT_BODY,
57 &format!("use of `#[inline]` on trait method `{}` which has no body", name),
59 db.suggest_remove_item(cx, attr.span, "remove");