diff options
| author | Robert Bastian <robertbastian@google.com> | 2023-01-09 21:29:42 +0100 |
|---|---|---|
| committer | Robert Bastian <robertbastian@google.com> | 2023-01-09 21:29:42 +0100 |
| commit | 53c12e085ab9595dff369f26046038afa20e8e5c (patch) | |
| tree | 88940897cc734e9aaafb21fa59ef25f20513fcc3 | |
| parent | 41b2a3d9fe20784bb1be0ac87a15fea015c3eac2 (diff) | |
| download | rust-53c12e085ab9595dff369f26046038afa20e8e5c.tar.gz rust-53c12e085ab9595dff369f26046038afa20e8e5c.zip | |
hash xor peq
| -rw-r--r-- | clippy_lints/src/derive.rs | 10 | ||||
| -rw-r--r-- | tests/ui/derive_hash_xor_eq.rs | 19 | ||||
| -rw-r--r-- | tests/ui/derive_hash_xor_eq.stderr | 32 |
3 files changed, 3 insertions, 58 deletions
diff --git a/clippy_lints/src/derive.rs b/clippy_lints/src/derive.rs index cf3483d4c00..e39a31a8c72 100644 --- a/clippy_lints/src/derive.rs +++ b/clippy_lints/src/derive.rs @@ -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); diff --git a/tests/ui/derive_hash_xor_eq.rs b/tests/ui/derive_hash_xor_eq.rs index 813ddc56646..0804e3cffa1 100644 --- a/tests/ui/derive_hash_xor_eq.rs +++ b/tests/ui/derive_hash_xor_eq.rs @@ -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() {} diff --git a/tests/ui/derive_hash_xor_eq.stderr b/tests/ui/derive_hash_xor_eq.stderr index 16c92397804..16965aa42d8 100644 --- a/tests/ui/derive_hash_xor_eq.stderr +++ b/tests/ui/derive_hash_xor_eq.stderr @@ -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 |
