-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add as_mut
methods to the std::cell
structs
#32565
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
(rust_highfive has picked a reviewer for you, use r? to override) |
Would it make sense to make Cell implement One advantage is simplified syntax: A possible disadvantage is that it is surprising for a type to implement Edit: Or, it could implement |
Implementing |
/// ``` | ||
#[inline] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub unsafe fn into_inner(self) -> T { | ||
pub fn into_inner(self) -> T { |
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.
This is a stable function so it cannot change.
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.
Removing an unsafe
qualifier shouldn't be a breaking change, right? What code could it break?
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.
In theory at least it could break code like this:
let f: unsafe fn(Cell<u8>) -> u8 = Cell::<u8>::into_inner;
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.
Ok, fair enough.
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.
Theoretical break isn't enough for it to be considered a major change (see https://github.com/rust-lang/rfcs/blob/master/text/1105-api-evolution.md ), but the RFC does not cover this case.
Thanks for the PR @tbu-! I don't think we can change |
Since new users are often confused by special case mutation methods like this (in my experience), the docs need to be clear somehow that this is a special case and regular modification of a Cell uses .set(). |
The libs team discussed this PR during triage today, and the conclusions were:
Could you make those changes @tbu- and I'll merge? Thanks again for the PR! |
I made those changes. Note that I also modified the Also, I want to ask whether you really want to name these functions The style document you referenced seems horribly out of date, it tells us to use |
@tbu- no, let's leave |
This is safe since the borrow checker ensures that we have the only mutable reference to the struct, thus we can safely borrow its interior. Tracking issue is rust-lang#33444.
@alexcrichton Updated. |
⌛ Testing commit 9370d3a with merge c02ee81... |
⛄ The build was interrupted to prioritize another pull request. |
Add `as_mut` methods to the `std::cell` structs This is safe since the borrow checking ensures that we have the only mutable reference to the struct, thus we can safely borrow its interior.
This is safe since the borrow checking ensures that we have the only
mutable reference to the struct, thus we can safely borrow its interior.