-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement Eq for Cell and RefCell. #25744
Conversation
`core::cell::Cell<T>` and `core::cell::RefCell<T>` currently implement `PartialEq` when `T` does, and just defer to comparing `T` values. There is no reason the same shouldn’t apply to `Eq`. This enables `#[derive(Eq, PartialEq)]` on e.g. structs that have a `RefCell` field.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
There might be a reason why |
@tbu- I don’t understand how that’s more of a problem for |
@SimonSapin |
It’s not clear to me that “don’t panic” is a promise that |
Well, it'd be useful for |
Anyway, here is how I came to this:
If there is a good reason not to implement |
I think that the cc @rust-lang/libs, do others have a strong opinion one way or another about this? |
I'm looking over the existing impls for |
I remember that |
The We could either treat it as "this should have never existed, and we're not going to add any more delegating trait implementations", or decide that it's fine, in which case we should probably add on impls of |
I consider the So, I'm +1 for adding these impls. |
@sfackler in the past we've found that omitting implementations of core traits from core types (e.g. |
I'm a bit leery in general of invisible sources of panics. |
True, although technically this PR introduces 0 extra panics because |
fwiw unsafe code already needs to guard against this sort of thing because "you never know". As such adding this is basically a "no-lose" scenario to me. |
`core::cell::Cell<T>` and `core::cell::RefCell<T>` currently implement `PartialEq` when `T` does, and just defer to comparing `T` values. There is no reason the same shouldn’t apply to `Eq`. This enables `#[derive(Eq, PartialEq)]` on e.g. structs that have a `RefCell` field. r? @alexcrichton I’m unsure what to do with `#[stable]` attributes on `impl`s. `impl`s generated by `#[derive]` don’t have them.
core::cell::Cell<T>
andcore::cell::RefCell<T>
currently implementPartialEq
whenT
does, and just defer to comparingT
values. There is no reason the same shouldn’t apply toEq
.This enables
#[derive(Eq, PartialEq)]
on e.g. structs that have aRefCell
field.r? @alexcrichton
I’m unsure what to do with
#[stable]
attributes onimpl
s.impl
s generated by#[derive]
don’t have them.