-
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 more explanation on RefCell::get_mut #40634
Conversation
src/libcore/cell.rs
Outdated
@@ -818,6 +818,12 @@ impl<T: ?Sized> RefCell<T> { | |||
/// This call borrows `RefCell` mutably (at compile-time) so there is no | |||
/// need for dynamic checks. | |||
/// | |||
/// However be cautious: this method expect `self` to be mutable, which is |
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.
s/expect/expects
bb40d11
to
52cf2a9
Compare
I think the real issue with #40203 is
That is, we need to explain when you would use this method, not just point out that it needs mutable self. |
Hi @GuillaumeGomez! It looks like @steveklabnik is suggesting some changes to this PR. Just wanted to send a ping to keep this on your radar! |
52cf2a9
to
0b9009e
Compare
Updated (finally!). |
Nevermind, errors are network related. Restarted the build. |
@bors: r+ rollup |
📌 Commit 0b9009e has been approved by |
🔒 Merge conflict |
0b9009e
to
3ad844c
Compare
Not sure what went wrong in here... I rebased just in case. @bors: r=steveklabnik rollup |
📌 Commit 3ad844c has been approved by |
Add more explanation on RefCell::get_mut Fixes #40203. r? @rust-lang/docs
☀️ Test successful - status-appveyor, status-travis |
Tone down explanation on RefCell::get_mut The language around `RefCell::get_mut` is remarkably sketchy and especially to the novice seems to quite strongly discourage using the method ("be cautious", "Also, please be aware", "special circumstances", "usually not what you want"). It was added six years ago in rust-lang#40634 due to confusion about when to use `get_mut` and `borrow_mut`. While its signature limits the use-cases for `get_mut`, there is no chance for a safety footgun, and readers can be made aware of `borrow_mut` more softly. I've also just sent a [PR](rust-lang/rust-clippy#9044) to lint situations where `get_mut` could be used to improve ergonomics and performance. So this PR tones down the language around `get_mut` and also brings it more in line with [`std::sync::Mutex::get_mut()`](https://doc.rust-lang.org/stable/std/sync/struct.Mutex.html#method.get_mut).
Tone down explanation on RefCell::get_mut The language around `RefCell::get_mut` is remarkably sketchy and especially to the novice seems to quite strongly discourage using the method ("be cautious", "Also, please be aware", "special circumstances", "usually not what you want"). It was added six years ago in rust-lang#40634 due to confusion about when to use `get_mut` and `borrow_mut`. While its signature limits the use-cases for `get_mut`, there is no chance for a safety footgun, and readers can be made aware of `borrow_mut` more softly. I've also just sent a [PR](rust-lang/rust-clippy#9044) to lint situations where `get_mut` could be used to improve ergonomics and performance. So this PR tones down the language around `get_mut` and also brings it more in line with [`std::sync::Mutex::get_mut()`](https://doc.rust-lang.org/stable/std/sync/struct.Mutex.html#method.get_mut).
Fixes #40203.
r? @rust-lang/docs