File tree 3 files changed +3
-58
lines changed
3 files changed +3
-58
lines changed Original file line number Diff line number Diff line change @@ -243,7 +243,7 @@ fn check_hash_peq<'tcx>(
243
243
cx. tcx. for_each_relevant_impl( peq_trait_def_id, ty, |impl_id| {
244
244
let peq_is_automatically_derived = cx. tcx. has_attr( impl_id, sym:: automatically_derived) ;
245
245
246
- if peq_is_automatically_derived == hash_is_automatically_derived {
246
+ if !hash_is_automatically_derived || peq_is_automatically_derived {
247
247
return ;
248
248
}
249
249
@@ -252,17 +252,11 @@ fn check_hash_peq<'tcx>(
252
252
// Only care about `impl PartialEq<Foo> for Foo`
253
253
// For `impl PartialEq<B> for A, input_types is [A, B]
254
254
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
-
261
255
span_lint_and_then(
262
256
cx,
263
257
DERIVE_HASH_XOR_EQ ,
264
258
span,
265
- mess ,
259
+ "you are deriving `Hash` but have implemented `PartialEq` explicitly" ,
266
260
|diag| {
267
261
if let Some ( local_def_id) = impl_id. as_local( ) {
268
262
let hir_id = cx. tcx. hir( ) . local_def_id_to_hir_id( local_def_id) ;
Original file line number Diff line number Diff line change @@ -34,23 +34,4 @@ impl std::hash::Hash for Bah {
34
34
fn hash < H : std:: hash:: Hasher > ( & self , _: & mut H ) { }
35
35
}
36
36
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
-
56
37
fn main ( ) { }
Original file line number Diff line number Diff line change @@ -25,35 +25,5 @@ LL | impl PartialEq<Baz> for Baz {
25
25
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
26
26
= note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info)
27
27
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
59
29
You can’t perform that action at this time.
0 commit comments