]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/inline_fn_without_body.rs
Rollup merge of #72047 - Julian-Wollersberger:literal_error_reporting_cleanup, r...
[rust.git] / clippy_lints / src / inline_fn_without_body.rs
index afa8f234023bbafc40d78f3ba895dca1b74f2ddb..475610dda47535ee60e11b840234ca44ed2f49e6 100644 (file)
@@ -1,62 +1,47 @@
-// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 //! checks for `#[inline]` on trait methods without bodies
 
 use crate::utils::span_lint_and_then;
 use crate::utils::sugg::DiagnosticBuilderExt;
-use rustc::hir::*;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_tool_lint, lint_array};
+use rustc_ast::ast::Attribute;
 use rustc_errors::Applicability;
-use syntax::ast::{Attribute, Name};
+use rustc_hir::{TraitFn, TraitItem, TraitItemKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::Symbol;
 
-/// **What it does:** Checks for `#[inline]` on trait methods without bodies
-///
-/// **Why is this bad?** Only implementations of trait methods may be inlined.
-/// The inline attribute is ignored for trait methods without bodies.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// trait Animal {
-///     #[inline]
-///     fn name(&self) -> &'static str;
-/// }
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for `#[inline]` on trait methods without bodies
+    ///
+    /// **Why is this bad?** Only implementations of trait methods may be inlined.
+    /// The inline attribute is ignored for trait methods without bodies.
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// trait Animal {
+    ///     #[inline]
+    ///     fn name(&self) -> &'static str;
+    /// }
+    /// ```
     pub INLINE_FN_WITHOUT_BODY,
     correctness,
     "use of `#[inline]` on trait methods without bodies"
 }
 
-#[derive(Copy, Clone)]
-pub struct Pass;
-
-impl LintPass for Pass {
-    fn get_lints(&self) -> LintArray {
-        lint_array!(INLINE_FN_WITHOUT_BODY)
-    }
-}
+declare_lint_pass!(InlineFnWithoutBody => [INLINE_FN_WITHOUT_BODY]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
-    fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
-        if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
+impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody {
+    fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem<'_>) {
+        if let TraitItemKind::Fn(_, TraitFn::Required(_)) = item.kind {
             check_attrs(cx, item.ident.name, &item.attrs);
         }
     }
 }
 
-fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) {
+fn check_attrs(cx: &LateContext<'_, '_>, name: Symbol, attrs: &[Attribute]) {
     for attr in attrs {
-        if attr.name() != "inline" {
+        if !attr.check_name(sym!(inline)) {
             continue;
         }
 
@@ -65,8 +50,8 @@ fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) {
             INLINE_FN_WITHOUT_BODY,
             attr.span,
             &format!("use of `#[inline]` on trait method `{}` which has no body", name),
-            |db| {
-                db.suggest_remove_item(cx, attr.span, "remove", Applicability::MachineApplicable);
+            |diag| {
+                diag.suggest_remove_item(cx, attr.span, "remove", Applicability::MachineApplicable);
             },
         );
     }