-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
std::sync::OnceLock
is Eq
but not Hash
#131959
Comments
The It seems reasonable to implement Probably worth documenting that equality behavior as well, I imagine! @rustbot claim |
Right! Sorry, I realized I misinterpreted your comment about Looking at implementing this, though, I've realized there's a precedent for this: Might be reasonable to implement @rustbot release-assignment At risk of favoring the status quo, do you have a use case for needing |
Mostly API completeness. I had a design that involved putting these things in a hashmap for later removal and processing, but ended up shifting away from it anyway. |
…ck, r=Mark-Simulacrum Document `PartialEq` impl for `OnceLock` Adds documentation to `std::sync::OnceLock`'s `PartialEq` implementation: specifies publicly that `OnceLock`s are compared based on their contents, and nothing else. Created in response to, but not directly related to, rust-lang#131959. ## ne This doesn't create and document `PartialEq::ne`. There's precedent for this in [`RefCell`](https://doc.rust-lang.org/std/cell/struct.RefCell.html#impl-PartialEq-for-RefCell%3CT%3E).
Rollup merge of rust-lang#132019 - daboross:document-partialeq-oncelock, r=Mark-Simulacrum Document `PartialEq` impl for `OnceLock` Adds documentation to `std::sync::OnceLock`'s `PartialEq` implementation: specifies publicly that `OnceLock`s are compared based on their contents, and nothing else. Created in response to, but not directly related to, rust-lang#131959. ## ne This doesn't create and document `PartialEq::ne`. There's precedent for this in [`RefCell`](https://doc.rust-lang.org/std/cell/struct.RefCell.html#impl-PartialEq-for-RefCell%3CT%3E).
The standard library type
std::sync::OnceLock
isEq
but notHash
. From a theoretical and practical perspective, it should probably be both or neither.The argument for neither is that the result of
Eq
can change because of a different thread as soon as it is returned. Similarly, the value ofHash
can change between comparison of theHash
and a follow up comparison withEq
. Both of these are expected short-comings of types that can be changed by other threads.The argument for both is that
Hash
is fundamentally a property related to equality and not rules out usages in containers where there are some external invariants that guarantee the desired behavior.The text was updated successfully, but these errors were encountered: