-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Some small nits to the borrowck suggestions for mutating a map through index #134945
Merged
+30
−21
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
rustbot
added
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Dec 31, 2024
compiler-errors
commented
Dec 31, 2024
= help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API | ||
help: to modify a `HashMap<&str, String>` use `.get_mut()` | ||
| | ||
LL | if let Some(val) = map.get_mut("peter") { val.clear(); }; |
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.
Very annoying to suggest removing that ;
, so I'm gonna leave that out. It doesn't hurt.
lqd
reviewed
Dec 31, 2024
compiler-errors
force-pushed
the
map-mutate-nits
branch
from
December 31, 2024 02:21
5b47c1d
to
f28e13b
Compare
@bors r+ |
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
Dec 31, 2024
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Jan 1, 2025
…=estebank Some small nits to the borrowck suggestions for mutating a map through index 1. Suggesting users to either use `.insert` or `.get_mut` (which do totally different things) can be a bit of a footgun, so let's make that a bit more nuanced. 2. I find the suggestion of `.get_mut(|val| { *val = whatever; })` to be a bit awkward. I changed this to be an if-let instead. 3. Fix a bug which was suppressing the structured suggestion for some mutations via the index operator on `HashMap`/`BTreeMap`. r? estebank or reassign
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jan 1, 2025
Rollup of 7 pull requests Successful merges: - rust-lang#131439 (Remove allowing static_mut_refs lint) - rust-lang#133292 (E0277: suggest dereferencing function arguments in more cases) - rust-lang#134080 (Avoid use of LFS64 symbols on Emscripten) - rust-lang#134877 (add suggestion for wrongly ordered format parameters) - rust-lang#134926 (Update books) - rust-lang#134945 (Some small nits to the borrowck suggestions for mutating a map through index) - rust-lang#134979 (Provide structured suggestion for `impl Default` of type where all fields have defaults) r? `@ghost` `@rustbot` modify labels: rollup
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jan 1, 2025
Rollup of 6 pull requests Successful merges: - rust-lang#131439 (Remove allowing static_mut_refs lint) - rust-lang#133292 (E0277: suggest dereferencing function arguments in more cases) - rust-lang#134877 (add suggestion for wrongly ordered format parameters) - rust-lang#134945 (Some small nits to the borrowck suggestions for mutating a map through index) - rust-lang#134950 (bootstrap: Overhaul and simplify the `tool_check_step!` macro) - rust-lang#134979 (Provide structured suggestion for `impl Default` of type where all fields have defaults) r? `@ghost` `@rustbot` modify labels: rollup
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jan 1, 2025
Rollup merge of rust-lang#134945 - compiler-errors:map-mutate-nits, r=estebank Some small nits to the borrowck suggestions for mutating a map through index 1. Suggesting users to either use `.insert` or `.get_mut` (which do totally different things) can be a bit of a footgun, so let's make that a bit more nuanced. 2. I find the suggestion of `.get_mut(|val| { *val = whatever; })` to be a bit awkward. I changed this to be an if-let instead. 3. Fix a bug which was suppressing the structured suggestion for some mutations via the index operator on `HashMap`/`BTreeMap`. r? estebank or reassign
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-compiler
Relevant to the compiler 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.
.insert
or.get_mut
(which do totally different things) can be a bit of a footgun, so let's make that a bit more nuanced..get_mut(|val| { *val = whatever; })
to be a bit awkward. I changed this to be an if-let instead.HashMap
/BTreeMap
.r? estebank or reassign