1 use crate::utils::{is_automatically_derived, span_lint_hir};
2 use if_chain::if_chain;
4 use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
5 use rustc::{declare_lint_pass, declare_tool_lint};
8 /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
10 /// **Why is this bad?** `PartialEq::ne` is required to always return the
11 /// negated result of `PartialEq::eq`, which is exactly what the default
12 /// implementation does. Therefore, there should never be any need to
15 /// **Known problems:** None.
21 /// impl PartialEq for Foo {
22 /// fn eq(&self, other: &Foo) -> bool { ... }
23 /// fn ne(&self, other: &Foo) -> bool { !(self == other) }
26 pub PARTIALEQ_NE_IMPL,
28 "re-implementing `PartialEq::ne`"
31 declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]);
33 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PartialEqNeImpl {
34 fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
36 if let ItemKind::Impl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node;
37 if !is_automatically_derived(&*item.attrs);
38 if let Some(eq_trait) = cx.tcx.lang_items().eq_trait();
39 if trait_ref.path.res.def_id() == eq_trait;
41 for impl_item in impl_items {
42 if impl_item.ident.name == sym!(ne) {
48 "re-implementing `PartialEq::ne` is unnecessary",