Conversation
There was a problem hiding this comment.
@fredszaq that's a solid work!
One major concern should be addressed before merging this. Otherwise, the PR makes a very good impression!
Thank you very much for contributing this and being pedantic to the implementation!
UPD: The concern appeared to be not major and non-concern at all. Then, will try to merge it the next few days!
| Self { a: self_0, b: self_1, c: self_2 } => { | ||
| self_0.hash(state); | ||
| self_1.hash(state); | ||
| self_2.hash(state); |
There was a problem hiding this comment.
@fredszaq I think, deriving Hash is a little bit trickier than it seems to be.
For the correctness, we should definitely consider and work correctly with the prefix collisions. They also should have good coverage in tests, since seem to be quite error-prone to edge cases.
There was a problem hiding this comment.
Hmmm... okay, it seems that std impls for tuples doesn't bother with that. It's all up to "leaf" types to bother with such things.
Good, so we don't need to bother about that. However, some tests for such cases still would be good to see.
There was a problem hiding this comment.
The rustc also doesn't bother for its derived impls (pass -Zunpretty=expanded to rustc or see playground):
#[derive(Hash)]
struct Test {
a: u32,
b: u32,
}becomes
#![feature(prelude_import)]
extern crate std;
#[prelude_import]
use std::prelude::rust_2024::*;
struct Test {
a: u32,
b: u32,
}
#[automatically_derived]
impl ::core::hash::Hash for Test {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
::core::hash::Hash::hash(&self.a, state);
::core::hash::Hash::hash(&self.b, state)
}
}|
I'd like to PR support for |
|
Hey @tyranron, pinging back on this, anything I can do to help you get this merged ? |
Nah... I would like to, but don't see how you could possibly decrease the load on my current job for me to get back on this 😅 Anyway, thanks for asking! I will reall try to merge this on these weekends. |
|
No pressure^^ do not hesitate if you have any questions or want me to make changes ! |
Synopsis
This PR adds a new derive for the
Hashtrait. This does mostly the same as the derive bundled with rust std but with a few niceties :#[hash(skip)](also honors#[eq(skip)]and#[partial_eq(skip)]to ensure trait expectations)#[hash(with(my_custom_hash_function)]Solution
I used the
PartialEqderive as an example to implement this, didn't have to do exotic things to get things to workChecklist