1 //! checks for `#[inline]` on trait methods without bodies
5 use syntax::ast::{Attribute, Name};
6 use utils::span_lint_and_then;
7 use 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;
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) {
41 TraitItemKind::Method(_, TraitMethod::Required(_)) => {
42 check_attrs(cx, &item.name, &item.attrs);
49 fn check_attrs(cx: &LateContext, name: &Name, attrs: &[Attribute]) {
51 if attr.name().map_or(true, |n| n != "inline") {
57 INLINE_FN_WITHOUT_BODY,
59 &format!("use of `#[inline]` on trait method `{}` which has no body", name),
61 db.suggest_remove_item(cx, attr.span, "remove");