hash xor peq
This commit is contained in:
parent
41b2a3d9fe
commit
53c12e085a
@ -243,7 +243,7 @@ fn check_hash_peq<'tcx>(
|
||||
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {
|
||||
let peq_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived);
|
||||
|
||||
if peq_is_automatically_derived == hash_is_automatically_derived {
|
||||
if !hash_is_automatically_derived || peq_is_automatically_derived {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -252,17 +252,11 @@ fn check_hash_peq<'tcx>(
|
||||
// Only care about `impl PartialEq<Foo> for Foo`
|
||||
// For `impl PartialEq<B> for A, input_types is [A, B]
|
||||
if trait_ref.substs.type_at(1) == ty {
|
||||
let mess = if peq_is_automatically_derived {
|
||||
"you are implementing `Hash` explicitly but have derived `PartialEq`"
|
||||
} else {
|
||||
"you are deriving `Hash` but have implemented `PartialEq` explicitly"
|
||||
};
|
||||
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
DERIVE_HASH_XOR_EQ,
|
||||
span,
|
||||
mess,
|
||||
"you are deriving `Hash` but have implemented `PartialEq` explicitly",
|
||||
|diag| {
|
||||
if let Some(local_def_id) = impl_id.as_local() {
|
||||
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);
|
||||
|
@ -34,23 +34,4 @@ impl std::hash::Hash for Bah {
|
||||
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct Foo2;
|
||||
|
||||
trait Hash {}
|
||||
|
||||
// We don't want to lint on user-defined traits called `Hash`
|
||||
impl Hash for Foo2 {}
|
||||
|
||||
mod use_hash {
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
#[derive(PartialEq)]
|
||||
struct Foo3;
|
||||
|
||||
impl Hash for Foo3 {
|
||||
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -25,35 +25,5 @@ LL | impl PartialEq<Baz> for Baz {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: you are implementing `Hash` explicitly but have derived `PartialEq`
|
||||
--> $DIR/derive_hash_xor_eq.rs:33:1
|
||||
|
|
||||
LL | / impl std::hash::Hash for Bah {
|
||||
LL | | fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
note: `PartialEq` implemented here
|
||||
--> $DIR/derive_hash_xor_eq.rs:30:10
|
||||
|
|
||||
LL | #[derive(PartialEq)]
|
||||
| ^^^^^^^^^
|
||||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: you are implementing `Hash` explicitly but have derived `PartialEq`
|
||||
--> $DIR/derive_hash_xor_eq.rs:51:5
|
||||
|
|
||||
LL | / impl Hash for Foo3 {
|
||||
LL | | fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
|
||||
LL | | }
|
||||
| |_____^
|
||||
|
|
||||
note: `PartialEq` implemented here
|
||||
--> $DIR/derive_hash_xor_eq.rs:48:14
|
||||
|
|
||||
LL | #[derive(PartialEq)]
|
||||
| ^^^^^^^^^
|
||||
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user