-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Implement more traits for guard types #44780
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
Conversation
Implements Hash, PartialEq, Eq, PartialOrd, and Ord for Ref, RefMut, MutexGuard, RwLockReadGuard, RwLockWriteGuard Fixes rust-lang#24372
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @BurntSushi (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. Due to 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 the contribution instructions for more information. |
src/libcore/cell.rs
Outdated
} | ||
} | ||
|
||
#[stable(feature = "std_guard_impls_ext", since = "1.23.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these should be marked as unstable
with a tracking issue set, but I'll let anyone else in the team correct me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't track stability on impls of traits today so these are all insta-stable AFAIK; no need to change anything.
src/libcore/cell.rs
Outdated
} | ||
} | ||
|
||
#[stable(feature = "std_guard_impls_ext", since = "1.23.0")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless you expect this PR will stay open for 20 days, the since
field should still be 1.22.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
This all seems fine to me, but I'm kind of surprised we didn't already have these impls. @marcusbuffett Could you maybe elaborate on the use case for wanting each of these impls for these types? cc @rust-lang/libs Is there a reason why we don't have these impls already or is it just that nobody has added them yet? |
@BurntSushi Beyond pointing to the issue (#24372), I can't really elaborate much – I just searched for |
Seems like a find idea to me! I think we just haven't gotten around to this previously |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems okay to me. Thanks!
Ok we got a chance to discuss this during the libs triage meeting today. In discussing this we ended up being increasingly wary of the guideline we set forth to add these trait impls and ended up concluding that we may not wish to add these at this time. These implementations, as added here, wouldn't enable something like The possibility of specialization in the future may end up providing a solution to this problem, and @aturon also mentioned that the lang team is going to be working during the impl period on "deref coercion ergonomics" to alleviate much of the need for these impls in the first place. In light of all that I'm going to close this for now and we'll likely be removing the guideline indicating that these traits should be implemented temporarily. Regardless though thanks for the PR @marcusbuffett! |
Implements
Hash
,PartialEq
,Eq
,PartialOrd
, andOrd
forRef
,RefMut
,MutexGuard
,RwLockReadGuard
,RwLockWriteGuard
.Fixes #24372
Bit of a rust noob, quick questions:
Preferred style wrt
x.deref()
or*x
? I went with*
unless it was going to be something too weird like&**
.hash::Hash
orHash
? I see thatfmt::Display
andfmt::Debug
are used for the Display and Debug traits, should I prefer that syntax instead?I saw all the other implementations use
#[inline]
and I just followed suit, any rules of thumb here, or is it just "use inline everywhere always?"I didn't see anything in the issue that said exactly what types needed these traits, so I just went with all the types that got
Debug
andDisplay
in this commit: 14df549, any more types that need these traits?