3 use utils::{is_automatically_derived, span_lint};
5 /// **What it does:** Checks for manual re-implementations of `PartialEq::ne`.
7 /// **Why is this bad?** `PartialEq::ne` is required to always return the
8 /// negated result of `PartialEq::eq`, which is exactly what the default
9 /// implementation does. Therefore, there should never be any need to
12 /// **Known problems:** None.
18 /// impl PartialEq for Foo {
19 /// fn eq(&self, other: &Foo) -> bool { ... }
20 /// fn ne(&self, other: &Foo) -> bool { !(self == other) }
24 pub PARTIALEQ_NE_IMPL,
26 "re-implementing `PartialEq::ne`"
29 #[derive(Clone, Copy)]
32 impl LintPass for Pass {
33 fn get_lints(&self) -> LintArray {
34 lint_array!(PARTIALEQ_NE_IMPL)
38 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
39 fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
41 let ItemImpl(_, _, _, _, Some(ref trait_ref), _, ref impl_items) = item.node,
42 !is_automatically_derived(&*item.attrs),
43 let Some(eq_trait) = cx.tcx.lang_items.eq_trait(),
44 trait_ref.path.def.def_id() == eq_trait
46 for impl_item in impl_items {
47 if impl_item.name == "ne" {
51 "re-implementing `PartialEq::ne` is unnecessary")