-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r? @m-ou-se (rust-highfive has picked a reviewer for you, use r? to override) |
This is great. Thank you! @bors r+ rollup |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 useget_mut
andborrow_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 ofborrow_mut
more softly. I've also just sent a PR to lint situations whereget_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 withstd::sync::Mutex::get_mut()
.