-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add swap
method for Cell
#39716
Add swap
method for Cell
#39716
Conversation
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. 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
let temp = unsafe { mem::uninitialized() }; | ||
let o = other.replace(temp); | ||
let s = self.replace(o); | ||
other.set(s); |
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.
The value in other
is currently garbage and this will drop it.
You could do mem::forget(other.replace(s))
, or this function could just be unsafe { ptr::swap(self.as_ptr(), other.as_ptr()); }
(after the pointer equality check of course)
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.
Thank you! I'll fix this.
Oh it looks like |
Thanks for the PR @F001! This seems like reasonable functionality to me. Thoughts @rust-lang/libs? |
I think this seems reasonable to me. Should this gets it own feature separate from |
@whataloadofwhat Thank you for your help! I was very busy yesterday, and submitted the code in a hurry. Even didn't try to compile. That's my fault! @BurntSushi Is "cell_swap" a reasonable name? Should I also open an issue to track this feature? |
Off the topic, I'm not sure the methods |
I can't see why |
This API seems good. I personally think it can go under the existing feature; it's almost certain to be stabilized together. We can always shard later if need be. |
@bors: r+ |
📌 Commit a5e8bbf has been approved by |
@bors rollup |
Add `swap` method for `Cell` Addition to rust-lang#39264 r? @alexcrichton
⌛ Testing commit a5e8bbf with merge f7c8beb... |
💔 Test failed - status-travis |
… On Mon, Feb 13, 2017 at 2:56 AM, bors ***@***.***> wrote:
💔 Test failed - status-travis
<https://travis-ci.org/rust-lang/rust/builds/201050096>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#39716 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAD95Jk8vf1vyvf5UFMkY8YYOiRYPK4Mks5rcBqogaJpZM4L9JuV>
.
|
Add `swap` method for `Cell` Addition to rust-lang#39264 r? @alexcrichton
I made a PR for this: #39793 |
Hey, I was going to write an RFC for this. Apparently it didn't need one? |
@glaebhoerl Yeah -- it's hard to draw a firm line here, but once we have a basic API surface (like the updated one for |
The PR above is is insta-stable, isn't it? It is relaxing trait bounds of methods, AFAIK this can't even be flagged as unstable... |
@RalfJung oh in this case the method is tagged |
One of the three is. The others are not. (I am talking just about my PR here, about what I quoted above -- not about |
Oh sorry, then yeah, those methods (with relaxed bounds) are instantly stable (the libs team discussed this though and is ok with that) |
Addition to #39264
r? @alexcrichton