Skip to content
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

Merged
merged 1 commit into from
Feb 13, 2017
Merged

Add swap method for Cell #39716

merged 1 commit into from
Feb 13, 2017

Conversation

F001
Copy link
Contributor

@F001 F001 commented Feb 10, 2017

Addition to #39264

r? @alexcrichton

@rust-highfive
Copy link
Collaborator

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.

let temp = unsafe { mem::uninitialized() };
let o = other.replace(temp);
let s = self.replace(o);
other.set(s);
Copy link

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)

Copy link
Contributor Author

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.

@ghost
Copy link

ghost commented Feb 10, 2017

Oh it looks like Cell::as_ptr is still only implemented for T: Copy. Sorry about that.

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Feb 11, 2017
@alexcrichton
Copy link
Member

Thanks for the PR @F001! This seems like reasonable functionality to me. Thoughts @rust-lang/libs?

@BurntSushi
Copy link
Member

I think this seems reasonable to me. Should this gets it own feature separate from move_cell though?

@F001
Copy link
Contributor Author

F001 commented Feb 11, 2017

@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?

@F001
Copy link
Contributor Author

F001 commented Feb 11, 2017

Off the topic, I'm not sure the methods as_ptr(), get_mut() and default() should still hold the Copy constraint, according to the recent extension of Cell type. @BurntSushi , what do you think of that?

@pitdicker
Copy link
Contributor

I can't see why as_ptr(), get_mut() and default() would require copy, and I also think from() would be okay. But don't take my word for it...

@aturon
Copy link
Member

aturon commented Feb 11, 2017

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.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 12, 2017

📌 Commit a5e8bbf has been approved by alexcrichton

@eddyb
Copy link
Member

eddyb commented Feb 13, 2017

@bors rollup

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 13, 2017
@bors
Copy link
Contributor

bors commented Feb 13, 2017

⌛ Testing commit a5e8bbf with merge f7c8beb...

@bors
Copy link
Contributor

bors commented Feb 13, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

alexcrichton commented Feb 13, 2017 via email

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Feb 13, 2017
@RalfJung
Copy link
Member

I'm not sure the methods as_ptr(), get_mut() and default() should still hold the Copy constraint, according to the recent extension of Cell type.

I made a PR for this: #39793

bors added a commit that referenced this pull request Feb 13, 2017
Rollup of 5 pull requests

- Successful merges: #39716, #39758, #39759, #39774, #39784
- Failed merges:
@bors bors merged commit a5e8bbf into rust-lang:master Feb 13, 2017
@glaebhoerl
Copy link
Contributor

Hey, I was going to write an RFC for this. Apparently it didn't need one?

@aturon
Copy link
Member

aturon commented Feb 22, 2017

@glaebhoerl Yeah -- it's hard to draw a firm line here, but once we have a basic API surface (like the updated one for Cell), additions in the same spirit can generally go through a PR. Of course, as with anything else they start unstable and there's the full FCP for stabilization later on.

@RalfJung
Copy link
Member

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...

@alexcrichton
Copy link
Member

@RalfJung oh in this case the method is tagged #[unstable], so the method should be unstable for awhile

@RalfJung
Copy link
Member

One of the three is. The others are not. (I am talking just about my PR here, about what I quoted above -- not about swap, which my PR does not touch.)

@alexcrichton
Copy link
Member

Oh sorry, then yeah, those methods (with relaxed bounds) are instantly stable

(the libs team discussed this though and is ok with that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants