]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/partialeq_ne_impl.rs
Auto merge of #3946 - rchaser53:issue-3920, r=flip1995
[rust.git] / clippy_lints / src / partialeq_ne_impl.rs
index 8b2e5f9c3569af1dbdb2bb4ad60c2d39819cdb42..2f034b9f1aac51d01e03db025943b83c428974ad 100644 (file)
@@ -1,28 +1,28 @@
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_tool_lint, lint_array};
+use crate::utils::{is_automatically_derived, span_lint_hir};
 use if_chain::if_chain;
 use rustc::hir::*;
-use crate::utils::{is_automatically_derived, span_lint};
+use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
+use rustc::{declare_tool_lint, lint_array};
 
-/// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
-///
-/// **Why is this bad?** `PartialEq::ne` is required to always return the
-/// negated result of `PartialEq::eq`, which is exactly what the default
-/// implementation does. Therefore, there should never be any need to
-/// re-implement it.
-///
-/// **Known problems:** None.
-///
-/// **Example:**
-/// ```rust
-/// struct Foo;
-///
-/// impl PartialEq for Foo {
-///    fn eq(&self, other: &Foo) -> bool { ... }
-///    fn ne(&self, other: &Foo) -> bool { !(self == other) }
-/// }
-/// ```
 declare_clippy_lint! {
+    /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
+    ///
+    /// **Why is this bad?** `PartialEq::ne` is required to always return the
+    /// negated result of `PartialEq::eq`, which is exactly what the default
+    /// implementation does. Therefore, there should never be any need to
+    /// re-implement it.
+    ///
+    /// **Known problems:** None.
+    ///
+    /// **Example:**
+    /// ```rust
+    /// struct Foo;
+    ///
+    /// impl PartialEq for Foo {
+    ///    fn eq(&self, other: &Foo) -> bool { ... }
+    ///    fn ne(&self, other: &Foo) -> bool { !(self == other) }
+    /// }
+    /// ```
     pub PARTIALEQ_NE_IMPL,
     complexity,
     "re-implementing `PartialEq::ne`"
@@ -35,6 +35,10 @@ impl LintPass for Pass {
     fn get_lints(&self) -> LintArray {
         lint_array!(PARTIALEQ_NE_IMPL)
     }
+
+    fn name(&self) -> &'static str {
+        "PartialEqNeImpl"
+    }
 }
 
 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
@@ -47,10 +51,13 @@ fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
             then {
                 for impl_item in impl_items {
                     if impl_item.ident.name == "ne" {
-                        span_lint(cx,
-                                  PARTIALEQ_NE_IMPL,
-                                  impl_item.span,
-                                  "re-implementing `PartialEq::ne` is unnecessary")
+                        span_lint_hir(
+                            cx,
+                            PARTIALEQ_NE_IMPL,
+                            impl_item.id.hir_id,
+                            impl_item.span,
+                            "re-implementing `PartialEq::ne` is unnecessary",
+                        );
                     }
                 }
             }