]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/partialeq_ne_impl.rs
Rollup merge of #83092 - petrochenkov:qspan, r=estebank
[rust.git] / clippy_lints / src / partialeq_ne_impl.rs
index 1091ed0d6de9cea7bd1e30ec03e7c102c303d541..aca1ed5ca6563144b4e3e9fc3a925f816a05ffd9 100644 (file)
@@ -1,8 +1,9 @@
 use crate::utils::{is_automatically_derived, span_lint_hir};
 use if_chain::if_chain;
-use rustc::hir::*;
-use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
-use rustc::{declare_lint_pass, declare_tool_lint};
+use rustc_hir::{Impl, Item, ItemKind};
+use rustc_lint::{LateContext, LateLintPass};
+use rustc_session::{declare_lint_pass, declare_tool_lint};
+use rustc_span::sym;
 
 declare_clippy_lint! {
     /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
@@ -19,7 +20,7 @@
     /// struct Foo;
     ///
     /// impl PartialEq for Foo {
-    ///    fn eq(&self, other: &Foo) -> bool { ... }
+    ///    fn eq(&self, other: &Foo) -> bool { true }
     ///    fn ne(&self, other: &Foo) -> bool { !(self == other) }
     /// }
     /// ```
 
 declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]);
 
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PartialEqNeImpl {
-    fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
+impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl {
+    fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
         if_chain! {
-            if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node;
-            if !is_automatically_derived(&*item.attrs);
+            if let ItemKind::Impl(Impl { of_trait: Some(ref trait_ref), items: impl_items, .. }) = item.kind;
+            let attrs = cx.tcx.hir().attrs(item.hir_id());
+            if !is_automatically_derived(attrs);
             if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
             if trait_ref.path.res.def_id() == eq_trait;
             then {
                 for impl_item in impl_items {
-                    if impl_item.ident.name == sym!(ne) {
+                    if impl_item.ident.name == sym::ne {
                         span_lint_hir(
                             cx,
                             PARTIALEQ_NE_IMPL,
-                            impl_item.id.hir_id,
+                            impl_item.id.hir_id(),
                             impl_item.span,
                             "re-implementing `PartialEq::ne` is unnecessary",
                         );