Skip to content

Commit 53c12e0

Browse files
committed
hash xor peq
1 parent 41b2a3d commit 53c12e0

File tree

3 files changed

+3
-58
lines changed

3 files changed

+3
-58
lines changed

clippy_lints/src/derive.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ fn check_hash_peq<'tcx>(
243243
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {
244244
let peq_is_automatically_derived = cx.tcx.has_attr(impl_id, sym::automatically_derived);
245245

246-
if peq_is_automatically_derived == hash_is_automatically_derived {
246+
if !hash_is_automatically_derived || peq_is_automatically_derived {
247247
return;
248248
}
249249

@@ -252,17 +252,11 @@ fn check_hash_peq<'tcx>(
252252
// Only care about `impl PartialEq<Foo> for Foo`
253253
// For `impl PartialEq<B> for A, input_types is [A, B]
254254
if trait_ref.substs.type_at(1) == ty {
255-
let mess = if peq_is_automatically_derived {
256-
"you are implementing `Hash` explicitly but have derived `PartialEq`"
257-
} else {
258-
"you are deriving `Hash` but have implemented `PartialEq` explicitly"
259-
};
260-
261255
span_lint_and_then(
262256
cx,
263257
DERIVE_HASH_XOR_EQ,
264258
span,
265-
mess,
259+
"you are deriving `Hash` but have implemented `PartialEq` explicitly",
266260
|diag| {
267261
if let Some(local_def_id) = impl_id.as_local() {
268262
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);

tests/ui/derive_hash_xor_eq.rs

-19
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,4 @@ impl std::hash::Hash for Bah {
3434
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
3535
}
3636

37-
#[derive(PartialEq)]
38-
struct Foo2;
39-
40-
trait Hash {}
41-
42-
// We don't want to lint on user-defined traits called `Hash`
43-
impl Hash for Foo2 {}
44-
45-
mod use_hash {
46-
use std::hash::{Hash, Hasher};
47-
48-
#[derive(PartialEq)]
49-
struct Foo3;
50-
51-
impl Hash for Foo3 {
52-
fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
53-
}
54-
}
55-
5637
fn main() {}

tests/ui/derive_hash_xor_eq.stderr

+1-31
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,5 @@ LL | impl PartialEq<Baz> for Baz {
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2626
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
2727

28-
error: you are implementing `Hash` explicitly but have derived `PartialEq`
29-
--> $DIR/derive_hash_xor_eq.rs:33:1
30-
|
31-
LL | / impl std::hash::Hash for Bah {
32-
LL | | fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
33-
LL | | }
34-
| |_^
35-
|
36-
note: `PartialEq` implemented here
37-
--> $DIR/derive_hash_xor_eq.rs:30:10
38-
|
39-
LL | #[derive(PartialEq)]
40-
| ^^^^^^^^^
41-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
42-
43-
error: you are implementing `Hash` explicitly but have derived `PartialEq`
44-
--> $DIR/derive_hash_xor_eq.rs:51:5
45-
|
46-
LL | / impl Hash for Foo3 {
47-
LL | | fn hash<H: std::hash::Hasher>(&self, _: &mut H) {}
48-
LL | | }
49-
| |_____^
50-
|
51-
note: `PartialEq` implemented here
52-
--> $DIR/derive_hash_xor_eq.rs:48:14
53-
|
54-
LL | #[derive(PartialEq)]
55-
| ^^^^^^^^^
56-
= note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)
57-
58-
error: aborting due to 4 previous errors
28+
error: aborting due to 2 previous errors
5929

0 commit comments

Comments
 (0)