about summary refs log tree commit diff
path: root/clippy_lints/src/declared_lints.rs
diff options
context:
space:
mode:
authorQuinn Sinclair <me@partiallytyped.dev>2023-11-19 11:33:01 +0100
committerPartiallyTyped <me@partiallytyped.dev>2023-11-19 11:33:01 +0100
commit3c1e0afa58dbe1287c1e9a9ea704f9b76b6845cc (patch)
tree832bddb91b9eb56aa83343f921e5ca6417470c1d /clippy_lints/src/declared_lints.rs
parent6eb935a578f7b2fcd87377bd571c4ff1dec48982 (diff)
downloadrust-3c1e0afa58dbe1287c1e9a9ea704f9b76b6845cc.tar.gz
rust-3c1e0afa58dbe1287c1e9a9ea704f9b76b6845cc.zip
New Lint [`impl_hash_with_borrow_str_and_bytes`]
Implements a lint to prevent implementation of Hash, Borrow<str> and
Borrow<[u8]> as it breaks Borrow<T> "semantics". According to the book,
types that implement Borrow<A> and Borrow<B> must ensure equality of
borrow results under Eq,Ord and Hash.

> In particular Eq, Ord and Hash must be equivalent for borrowed and
owned values: x.borrow() == y.borrow() should give the same result as x == y.

In the same way, hash(x) == hash(x as Borrow<[u8]>) != hash(x as Borrow<str>).

changelog: newlint [`impl_hash_with_borrow_str_and_bytes`]
Diffstat (limited to 'clippy_lints/src/declared_lints.rs')
-rw-r--r--clippy_lints/src/declared_lints.rs1
1 files changed, 1 insertions, 0 deletions
diff --git a/clippy_lints/src/declared_lints.rs b/clippy_lints/src/declared_lints.rs
index 85854a0dfb7..55dedc0a658 100644
--- a/clippy_lints/src/declared_lints.rs
+++ b/clippy_lints/src/declared_lints.rs
@@ -204,6 +204,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
     crate::if_not_else::IF_NOT_ELSE_INFO,
     crate::if_then_some_else_none::IF_THEN_SOME_ELSE_NONE_INFO,
     crate::ignored_unit_patterns::IGNORED_UNIT_PATTERNS_INFO,
+    crate::impl_hash_with_borrow_str_and_bytes::IMPL_HASH_BORROW_WITH_STR_AND_BYTES_INFO,
     crate::implicit_hasher::IMPLICIT_HASHER_INFO,
     crate::implicit_return::IMPLICIT_RETURN_INFO,
     crate::implicit_saturating_add::IMPLICIT_SATURATING_ADD_INFO,