Skip to content

Stabilize or_insert_with_key - #78083

Merged
bors merged 4 commits into
rust-lang:masterfrom
ChaiTRex:master
Dec 19, 2020
Merged

Stabilize or_insert_with_key#78083
bors merged 4 commits into
rust-lang:masterfrom
ChaiTRex:master

Conversation

@ChaiTRex

Copy link
Copy Markdown
Contributor

Stabilizes the or_insert_with_key feature from #71024. This allows inserting key-derived values when a HashMap/BTreeMap entry is vacant.

The difference between this and .or_insert_with(|| ... ) is that this provides a reference to the key to the closure after it is moved with .entry(key_being_moved), avoiding the need to copy or clone the key.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @varkor

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 18, 2020
@jonas-schievinkjonas-schievink added A-collections Area: `std::collections` needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. relnotes Marks issues that should be documented in the release notes of the next release. T-libs-api [DEPRECATED; DO NOT USE] labels Oct 18, 2020
@varkor

Copy link
Copy Markdown
Contributor

This will needs a libs team sign-off.

r? @SimonSapin

@crlf0710crlf0710 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 7, 2020
@m-ou-se

Copy link
Copy Markdown
Member

@rfcbot merge

@rfcbot

rfcbot commented Nov 25, 2020

Copy link
Copy Markdown

Team member @m-ou-se has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbotrfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 25, 2020
@m-ou-se

Copy link
Copy Markdown
Member

Sorry for the delay! Unfortunately this missed 1.49. Can you update the stable versions to 1.50?

@ChaiTRex

Copy link
Copy Markdown
ContributorAuthor

@m-ou-se It is updated in the latest commit.

@BurntSushi

Copy link
Copy Markdown
Member

The difference between this and .or_insert_with(|| ... ) is that this provides a reference to the key to the closure after it is moved with .entry(key_being_moved), avoiding the need to copy or clone the key.

This seems like a useful bit of information that would be good to add to the docs.

@ChaiTRex

Copy link
Copy Markdown
ContributorAuthor

@BurntSushi How about this?

Ensures a value is in the entry by inserting, if empty, the result of the default function. This method allows for generating key-derived values for insertion by providing the default function a reference to the key that was moved during the .entry(key) method call.

The reference to the moved key is provided so that cloning or copying the key is unnecessary, unlike with .or_insert_with(|| ... ).

@BurntSushi

Copy link
Copy Markdown
Member

@ChaiTRex Thank you, that looks great to me!

@rfcbotrfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Dec 8, 2020
@rfcbot

Copy link
Copy Markdown

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbotrfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Dec 8, 2020
@rfcbotrfcbot added the finished-final-comment-period The final comment period is finished for this PR / Issue. label Dec 18, 2020
@rfcbot

Copy link
Copy Markdown

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@rfcbotrfcbot added to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Dec 18, 2020
@m-ou-se

Copy link
Copy Markdown
Member

@bors r+ rollup

@bors

bors commented Dec 18, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit f115be9 has been approved by m-ou-se

@borsbors 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 18, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Dec 19, 2020
Stabilize or_insert_with_key
Stabilizes the `or_insert_with_key` feature from rust-lang#71024. This allows inserting key-derived values when a `HashMap`/`BTreeMap` entry is vacant.
The difference between this and `.or_insert_with(|| ... )` is that this provides a reference to the key to the closure after it is moved with `.entry(key_being_moved)`, avoiding the need to copy or clone the key.
@JohnTitorJohnTitor mentioned this pull request Dec 19, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 19, 2020
Rollup of 7 pull requests
Successful merges:
- rust-lang#78083 (Stabilize or_insert_with_key)
- rust-lang#79211 (Add the "async" and "promise" doc aliases to `core::future::Future`)
- rust-lang#79612 (Switch some links in compiler/ to intra-doc links)
- rust-lang#80068 (Add `&mut` as an alias for 'reference' primitive)
- rust-lang#80129 (docs: Edit rustc_ast::token::Token)
- rust-lang#80133 (Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere)
- rust-lang#80155 (Fix typo)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 0765536 into rust-lang:masterDec 19, 2020
@rustbotrustbot added this to the 1.50.0 milestone Dec 19, 2020
@spastorinospastorino removed the to-announce Announce this issue on triage meeting label Dec 31, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-collectionsArea: `std::collections`disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.needs-fcpThis change is insta-stable, or significant enough to need a team FCP to proceed.relnotesMarks issues that should be documented in the release notes of the next release.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

12 participants

@ChaiTRex@rust-highfive@varkor@m-ou-se@rfcbot@BurntSushi@bors@spastorino@SimonSapin@crlf0710@jonas-schievink@rustbot