]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/inherent_impl.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / inherent_impl.rs
index 167259b73538df66bbf5ead10c5372a24133de1c..51d6c310cf628f0ec87c5971f0d7dd7874241e70 100644 (file)
@@ -1,40 +1,40 @@
 //! lint on inherent implementations
 
-use crate::rustc::hir::*;
-use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use crate::rustc::{declare_tool_lint, lint_array};
-use crate::rustc_data_structures::fx::FxHashMap;
-use std::default::Default;
-use crate::syntax_pos::Span;
 use crate::utils::span_lint_and_then;
+use rustc::hir::*;
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
+use rustc_data_structures::fx::FxHashMap;
+use std::default::Default;
+use syntax_pos::Span;
 
-/// **What it does:** Checks for multiple inherent implementations of a struct
-///
-/// **Why is this bad?** Splitting the implementation of a type makes the code harder to navigate.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// struct X;
-/// impl X {
-///     fn one() {}
-/// }
-/// impl X {
-///     fn other() {}
-/// }
-/// ```
-///
-/// Could be written:
-///
-/// ```rust
-/// struct X;
-/// impl X {
-///     fn one() {}
-///     fn other() {}
-/// }
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for multiple inherent implementations of a struct
+    ///
+    /// **Why is this bad?** Splitting the implementation of a type makes the code harder to navigate.
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// struct X;
+    /// impl X {
+    ///     fn one() {}
+    /// }
+    /// impl X {
+    ///     fn other() {}
+    /// }
+    /// ```
+    ///
+    /// Could be written:
+    ///
+    /// ```rust
+    /// struct X;
+    /// impl X {
+    ///     fn one() {}
+    ///     fn other() {}
+    /// }
+    /// ```
     pub MULTIPLE_INHERENT_IMPL,
     restriction,
     "Multiple inherent impl that could be grouped"
@@ -46,7 +46,9 @@ pub struct Pass {
 
 impl Default for Pass {
     fn default() -> Self {
-        Self { impls: FxHashMap::default() }
+        Self {
+            impls: FxHashMap::default(),
+        }
     }
 }
 
@@ -54,6 +56,10 @@ impl LintPass for Pass {
     fn get_lints(&self) -> LintArray {
         lint_array!(MULTIPLE_INHERENT_IMPL)
     }
+
+    fn name(&self) -> &'static str {
+        "MultipleInherientImpl"
+    }
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
@@ -78,11 +84,7 @@ fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx Crate) {
                 let mut impl_spans = impls
                     .iter()
                     .filter_map(|impl_def| self.impls.get(impl_def))
-                    .filter_map(|(span, generics)| if generics.params.len() == 0 {
-                        Some(span)
-                    } else {
-                        None
-                    });
+                    .filter_map(|(span, generics)| if generics.params.len() == 0 { Some(span) } else { None });
                 if let Some(initial_span) = impl_spans.nth(0) {
                     impl_spans.for_each(|additional_span| {
                         span_lint_and_then(
@@ -91,10 +93,7 @@ fn check_crate_post(&mut self, cx: &LateContext<'a, 'tcx>, krate: &'tcx Crate) {
                             *additional_span,
                             "Multiple implementations of this structure",
                             |db| {
-                                db.span_note(
-                                    *initial_span,
-                                    "First implementation here",
-                                );
+                                db.span_note(*initial_span, "First implementation here");
                             },
                         )
                     })