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

Tone down explanation on RefCell::get_mut #101389

Merged
merged 1 commit into from
Sep 20, 2022
Merged

Conversation

lukaslueg
Copy link
Contributor

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 #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 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().

@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 3, 2022
@rust-highfive
Copy link
Collaborator

r? @m-ou-se

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 3, 2022
@m-ou-se
Copy link
Member

m-ou-se commented Sep 19, 2022

This is great. Thank you!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Sep 19, 2022

📌 Commit 2c664bc has been approved by m-ou-se

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2022
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).
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 20, 2022
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#101389 (Tone down explanation on RefCell::get_mut)
 - rust-lang#101798 (Make `from_waker`, `waker` and `from_raw` unstably `const`)
 - rust-lang#101881 (Remove an unused struct field `late_bound`)
 - rust-lang#101904 (Add help for invalid inline argument)
 - rust-lang#101966 (Add unit test for identifier Unicode emoji diagnostics)
 - rust-lang#101979 (Update release notes for 1.64)
 - rust-lang#101985 (interpret: expose generate_stacktrace without full InterpCx)
 - rust-lang#102004 (Try to clarify what's new in 1.64.0 ffi types)
 - rust-lang#102005 (rustdoc: remove unused CSS `td.summary-column`)
 - rust-lang#102017 (Add all submodules to the list of directories tidy skips)
 - rust-lang#102019 (Remove backed off PRs from relnotes)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 27b1b04 into rust-lang:master Sep 20, 2022
@rustbot rustbot added this to the 1.66.0 milestone Sep 20, 2022
@lukaslueg lukaslueg deleted the rcgetmutdocs branch September 20, 2022 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants