-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
find_or_insert_with should return a &mut pointer #6394
Comments
nominating for production ready |
Just to be clear, these methods would be the same as |
If that's the case, then find_mut should disappear as well, and find should return &mut, etc? |
@metajack: |
accepted for backwards-compatible milestone |
My latest proposed patch in #6815 fixes this. |
… r=ebroto Add lint size_of_in_element_count Fixes rust-lang#6381 changelog: Add lint to check for using size_of::<T> or size_of_val::<T> in the count parameter to ptr::copy or ptr::copy_nonoverlapping, which take a count of Ts (And not a count of bytes) - \[X] Followed [lint naming conventions][lint_naming] - \[X] Added passing UI tests (including committed `.stderr` file) - \[ ] `cargo test` passes locally - \[X] Executed `cargo dev update_lints` - \[X] Added lint documentation - \[X] Run `cargo dev fmt` [lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints Running `cargo test` locally fails with this error: ``` running 1 test test fmt ... FAILED failures: ---- fmt stdout ---- status: exit code: 1 stdout: stderr: error: unable to unlink old fallback exe error: caused by: Access is denied. (os error 5) thread 'fmt' panicked at 'Formatting check failed. Run `cargo dev fmt` to update formatting.', tests\fmt.rs:32:5 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: fmt test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out ``` But I did run `cargo dev fmt`
Trying to satisfy the borrow checker in some cases leads to a little bit clumsy HashMap code. For example, if you want to find_or_insert but need to modify the value.
Here's an example where I had to work around this by using
contains_key
and thenfind_mut
andinsert
directly:https://gist.github.com/metajack/5555485#file-gistfile2-diff-L28-L45
I suggest adding
find_or_insert_mut
andfind_or_insert_with_mut
. It might be better to usefind_mut_or_insert
andfind_mut_or_insert_with
as names perhaps.The text was updated successfully, but these errors were encountered: