Uh oh!
There was an error while loading. Please reload this page.
Add pub fn ptr_eq(this: &Self, other: &Self) -> bool to Rc and Arc - #35992
Conversation
rust-highfive
commented
Aug 25, 2016
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @aturon (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. |
aturon
commented
Aug 25, 2016
cc @rust-lang/libs I feel like there's some history here -- e.g. it used to exist -- but I'm not sure when/why this was removed offhand. In general I think this is a nice convenience to provide. |
alexcrichton
commented
Aug 25, 2016
I guess I don't see a reason to not have these in the standard library, but conversely I don't see a particular reason to have these in the standard library either. I've written them from time to time as well, but I never felt like there was a footgun or anything, the implementation was pretty clear. |
Stebalien
commented
Aug 26, 2016
Here's a more general solution to the same problem (might make a useful crate): https://gist.github.com/61d5a030296ad3d5b0c3ea71c088c836 |
SimonSapin
commented
Aug 26, 2016
(Side question: I’ve pushed what I think fixes the doctests, but Yes, it is possible and not particularly difficult to implement outside the standard library, but it seems to be a pretty basic operation when dealing with reference-counted or garbage-collected things. Both Python and Java have operators ( And Rust’s The only (small) footgun that I know of is being tempted to make a single generic function that works for both |
aturon
commented
Aug 26, 2016
Agreed. I think we should ship it. |
Functionality seems fine to me. Is |
SimonSapin
commented
Aug 29, 2016
The |
alexcrichton
commented
Sep 12, 2016
Discussed at libs triage the conclusion was that these seem good to add. @Kimundi also pointed out that this is very similar to rust-lang/rfcs#1155 and we were also thinking it'd be good to add: fn std::mem::ptr_eq<T: ?Sized>(a:&T, b:&T) -> bool;@SimonSapin would you be interested in adding those methods as well? Also could you update the tracking issue reference here as well with a fresh issue? |
SimonSapin
commented
Sep 14, 2016
Sure, I can add this. Although in the RFC the arguments are Should these be three "features" and tracking issues, or just one? |
sfackler
commented
Sep 14, 2016
I kind of like |
SimonSapin
commented
Sep 14, 2016
Just to be clear however, I don’t think it works as a replacement for I’ll update the PR to add all three. |
sfackler
commented
Sep 14, 2016
Oh yeah, we absolutely want all three. |
6e292f4 to
bb8a439Comparebb8a439 to
8bb86c8CompareSimonSapin
commented
Sep 15, 2016
Filed #36497 and updated the PR. |
…rc`. Servo and Kuchiki have had helper functions doing this for some time.
8bb86c8 to
5ce9feeComparealexcrichton
commented
Sep 15, 2016
@bors: r+ |
bors
commented
Sep 15, 2016
📌 Commit 5ce9fee has been approved by |
bors
commented
Sep 15, 2016
⌛ Testing commit 5ce9fee with merge d1acabe... |
Add `pub fn ptr_eq(this: &Self, other: &Self) -> bool` to Rc and Arc Servo and Kuchiki have had helper functions doing this for some time.
bors
commented
Sep 15, 2016
Could this reliably be used to perform an equality check for functions using pointers? For example: fnein(){}fnzwei(){}fnmain(){println!("ein == zwei: {}", ein as*mut() == zwei as*mut());// falseprintln!("ein == zwei: {}", ein as*mut() == ein as*mut());// true}The above works on stable, so what I'm really wondering about is how reliably this can be used. |
Servo and Kuchiki have had helper functions doing this for some time.