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

Clarify the difference between get_mut and into_mut for OccupiedEntry #51312

Merged
merged 4 commits into from
Jun 3, 2018

Conversation

frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Jun 2, 2018

The examples for both hash_map::OccupiedEntry::get_mut and
hash_map::OccupiedEntry::into_mut were almost identical. This led to some
confusion over the difference, namely why you would ever use get_mut when
into_mut gives alonger lifetime. Reddit thread:
https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps

This commit adds two lines and a comment to the example, to show that the
entry object can be re-used after calling get_mut.

Closes #49745

The examples for both hash_map::OccupiedEntry::get_mut and
hash_map::OccupiedEntry::into_mut were almost identical. This led
to some confusion over the difference, namely why you would ever
use get_mut when into_mut gives alonger lifetime. Reddit thread:
https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps

This commit adds two lines and a comment to the example, to show
that the entry object can be re-used after calling get_mut.
@rust-highfive
Copy link
Collaborator

r? @cramertj

(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 Jun 2, 2018
@frewsxcv
Copy link
Member Author

frewsxcv commented Jun 2, 2018

This is a continuation of #49743.

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Looks good, thanks.

@dtolnay
Copy link
Member

dtolnay commented Jun 2, 2018

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 2, 2018

📌 Commit 5473fb4 has been approved by dtolnay

@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 Jun 2, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:47:01] ...........................................................................i........................
[00:47:06] ....................................................................................................
[00:47:11] ....................................................................................................
[00:47:18] ....................................................................................................
[00:47:22] ........i.................iiiiiiiii...................................................
[00:47:22] 
[00:47:22] travis_fold:start:test_ui_nll
travis_time:start:test_ui_nll
Check compiletest suite=ui mode=ui compare_mode=nll (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
[00:48:15] ...........................................................................i........................
[00:48:20] ....................................................................................................
[00:48:25] ....................................................................................................
[00:48:31] ....................................................................................................
[00:48:35] ........i.................iiiiiiiii...................................................
[00:48:35] 
[00:48:35]  finished in 72.973
[00:48:35] travis_fold:end:test_ui_nll

---
[01:27:54] travis_fold:end:stage0-linkchecker

[01:27:54] travis_time:end:stage0-linkchecker:start=1527975360216938164,finish=1527975363078293968,duration=2861355804

[01:27:59] std/collections/struct.HashMap.html:448: broken link fragment `#method.into_mut` pointing to `std/collections/struct.HashMap.html`
[01:27:59] std/collections/struct.BTreeMap.html:158: broken link fragment `#method.into_mut` pointing to `std/collections/struct.BTreeMap.html`
65412 ./src/llvm-emscripten/test/CodeGen
63940 ./obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps
63540 ./obj/build/x86_64-unknown-linux-gnu/stage2-tools
62124 ./obj/build/x86_64-unknown-linux-gnu/stage0-rustc/release

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@frewsxcv frewsxcv force-pushed the clarify-hash-map-entry-get-mut branch from 5473fb4 to 4974aab Compare June 2, 2018 22:08
@frewsxcv
Copy link
Member Author

frewsxcv commented Jun 2, 2018

Fixed the links in the latest force pushes

@bors r=dtolnay

@bors
Copy link
Contributor

bors commented Jun 2, 2018

📌 Commit 4974aab has been approved by dtolnay

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:44:53] ...........................................................................i........................
[00:44:58] ....................................................................................................
[00:45:04] ....................................................................................................
[00:45:10] ....................................................................................................
[00:45:15] ........i.................iiiiiiiii...................................................
[00:45:15] 
[00:45:15] travis_fold:start:test_ui_nll
travis_time:start:test_ui_nll
Check compiletest suite=ui mode=ui compare_mode=nll (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
---
[00:46:08] ...........................................................................i........................
[00:46:13] ....................................................................................................
[00:46:18] ....................................................................................................
[00:46:24] ....................................................................................................
[00:46:29] ........i.................iiiiiiiii...................................................
[00:46:29] 
[00:46:29]  finished in 73.648
[00:46:29] travis_fold:end:test_ui_nll

---
[01:23:47] travis_fold:end:stage0-linkchecker

[01:23:47] travis_time:end:stage0-linkchecker:start=1527982400831828395,finish=1527982403512645069,duration=2680816674

[01:23:52] std/collections/struct.BTreeMap.html:158: broken link fragment `#method.into_mut` pointing to `std/collections/struct.BTreeMap.html`

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@frewsxcv frewsxcv force-pushed the clarify-hash-map-entry-get-mut branch from 4974aab to dd88f88 Compare June 3, 2018 00:44
@frewsxcv
Copy link
Member Author

frewsxcv commented Jun 3, 2018

@bors r=dtolnay

@bors
Copy link
Contributor

bors commented Jun 3, 2018

📌 Commit dd88f88 has been approved by dtolnay

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 3, 2018
…-mut, r=dtolnay

Clarify the difference between get_mut and into_mut for OccupiedEntry

The examples for both hash_map::OccupiedEntry::get_mut and
hash_map::OccupiedEntry::into_mut were almost identical. This led to some
confusion over the difference, namely why you would ever use get_mut when
into_mut gives alonger lifetime. Reddit thread:
https://www.reddit.com/r/rust/comments/8a5swr/why_does_hashmaps

This commit adds two lines and a comment to the example, to show that the
entry object can be re-used after calling get_mut.

Closes rust-lang#49745
bors added a commit that referenced this pull request Jun 3, 2018
Rollup of 6 pull requests

Successful merges:

 - #51143 (Specify that packed types must derive, not implement, Copy)
 - #51226 (Make Layout's align a NonZeroUsize)
 - #51297 (Fix run button style)
 - #51306 (impl Default for &mut str)
 - #51312 (Clarify the difference between get_mut and into_mut for OccupiedEntry)
 - #51313 (use type name in E0599 enum variant suggestion)

Failed merges:
@bors bors merged commit dd88f88 into rust-lang:master Jun 3, 2018
@Phlosioneer
Copy link
Contributor

Thank you @frewsxcv for finishing this.

@dtolnay dtolnay assigned dtolnay and unassigned cramertj Mar 24, 2024
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusing lifetime on HashMap's Entry::get
6 participants