A lint to detect when a type implements all three of Hash
, Borrow<str>
and Borrow<[u8]>
#11710
Labels
A-lint
Area: New lints
Hash
, Borrow<str>
and Borrow<[u8]>
#11710
What it does
Detects when a type which implements
Hash
also implements bothBorrow<str>
andBorrow<[u8]>
.Advantage
It's impossible to implement both of these correctly, as
str
and[u8]
hash differently in incompatible ways, and implementingBorrow<T>
for your type guaratees that you hash equivalent toT
.This is worth adding because this impl is tempting to add, as the distinction between
Borrow
andAsRef
is very subtle, and theAsRef
impl for both is correct (as is implementing both for types which do not implementHash
).See BurntSushi/bstr#168 for some discussion (As this would not quite have caught the problem in that issue, it's possible my formulation of it is too narrow. For the most part, I am chucking this lint proposal over the wall, and am not tied to the specifics here).
Drawbacks
It's rather niche.
Example
is wrong, either remove any one of those impls to be correct.
The text was updated successfully, but these errors were encountered: