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 more explanation on RefCell::get_mut #40634

Merged
merged 1 commit into from
Apr 24, 2017

Conversation

GuillaumeGomez
Copy link
Member

Fixes #40203.

r? @rust-lang/docs

@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/expect/expects

@steveklabnik
Copy link
Member

I think the real issue with #40203 is

but I think it could be more explicit that get_mut is for special circumstances / usually not what you want. The name get_mut may tend to confuse newbies since it looks 'basic' and very similar to borrow_mut.

That is, we need to explain when you would use this method, not just point out that it needs mutable self.

@alexcrichton alexcrichton added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Apr 11, 2017
@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 14, 2017
@carols10cents
Copy link
Member

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!

@GuillaumeGomez
Copy link
Member Author

Updated (finally!).

@frewsxcv
Copy link
Member

frewsxcv commented Apr 20, 2017

Travis found errors.

Nevermind, errors are network related. Restarted the build.

@shepmaster shepmaster added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 21, 2017
@steveklabnik
Copy link
Member

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Apr 24, 2017

📌 Commit 0b9009e has been approved by steveklabnik

@bors
Copy link
Contributor

bors commented Apr 24, 2017

🔒 Merge conflict

@GuillaumeGomez
Copy link
Member Author

Not sure what went wrong in here... I rebased just in case.

@bors: r=steveklabnik rollup

@bors
Copy link
Contributor

bors commented Apr 24, 2017

📌 Commit 3ad844c has been approved by steveklabnik

@bors
Copy link
Contributor

bors commented Apr 24, 2017

⌛ Testing commit 3ad844c with merge 63c7721...

bors added a commit that referenced this pull request Apr 24, 2017
Add more explanation on RefCell::get_mut

Fixes #40203.

r? @rust-lang/docs
@bors
Copy link
Contributor

bors commented Apr 24, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: steveklabnik
Pushing 63c7721 to master...

@bors bors merged commit 3ad844c into rust-lang:master Apr 24, 2017
@GuillaumeGomez GuillaumeGomez deleted the refcell-docs branch April 24, 2017 16:57
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Sep 19, 2022
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).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 19, 2022
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants