Skip to content

feat: reimplement hash_map! macro#154322

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
m4rch3n1ng:hash-map-macro
Mar 30, 2026
Merged

feat: reimplement hash_map! macro#154322
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
m4rch3n1ng:hash-map-macro

Conversation

@m4rch3n1ng
Copy link
Copy Markdown
Contributor

@m4rch3n1ng m4rch3n1ng commented Mar 24, 2026

originally implemented in #144070, this had to be reverted in #148049 due to name ambiguity, as the macro was automatically put into the prelude. now, that #139493 has landed, it is possible to have a top-level macro, that is not exported by default, which should make it possible to reland this again.

implements #144032
implementation from #144070, original author has been added as co-author
effectively reverts #148049

Co-authored-by: stifskere <esteve@memw.es>
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 24, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 24, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 8 candidates

}};

( $( $key:expr => $value:expr ),* $(,)? ) => {{
let mut map = $crate::collections::HashMap::with_capacity(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm curious as to why this is implemented this way instead of using the From<[T;N]> impl. Wouldn't that be simpler, as it would remove the need for the repetition count machinery?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

see this comment on the thread of the original implementation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hah, yeah that's a good reason

Copy link
Copy Markdown
Member

@Mark-Simulacrum Mark-Simulacrum left a comment

Choose a reason for hiding this comment

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

Can you add a test case (or find one if it already exists, not sure) that confirms this (or a future PR) doesn't re-introduce the regression? It'll probably want to go in tests/ui.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 29, 2026

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@m4rch3n1ng
Copy link
Copy Markdown
Contributor Author

there's a test already in library/std/tests, which was added in #148049, or do you mean a different test?

@rustbot ready (i think)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 29, 2026
@Mark-Simulacrum
Copy link
Copy Markdown
Member

That works. Thanks for finding it!

@bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 29, 2026

📌 Commit 2e65734 has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Mar 29, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 29, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #154074 (don't drop arguments' temporaries in `dbg!`)
 - #154328 (rustdoc: add missing {os,target,target_env} values for cfg pretty printer)
 - #154540 (Fix invalid type suggestion for item nested in function)
 - #154549 (Add regression test for recursive lazy type alias normalization ICE)
 - #153373 (Fix LegacyKeyValueFormat report from docker build: powerpc)
 - #154322 (feat: reimplement `hash_map!` macro)
 - #154416 (Add `IoSplit` diagnostic item for `std::io::Split`)
 - #154486 (std_detect on AArch64 Darwin: Detect FEAT_SVE_B16B16)
 - #154508 (Fix ambiguous parsing in bootstrap.py)
 - #154518 (Panic in Hermit clock_gettime)
 - #154530 (update zulip link in `std` documentation)
@rust-bors rust-bors bot merged commit 880fe19 into rust-lang:main Mar 30, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 30, 2026
rust-timer added a commit that referenced this pull request Mar 30, 2026
Rollup merge of #154322 - m4rch3n1ng:hash-map-macro, r=Mark-Simulacrum

feat: reimplement `hash_map!` macro

originally implemented in #144070, this had to be reverted in #148049 due to name ambiguity, as the macro was automatically put into the prelude. now, that #139493 has landed, it is possible to have a top-level macro, that is not exported by default, which should make it possible to reland this again.

implements #144032
implementation from #144070, original author has been added as co-author
effectively reverts #148049
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 30, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#154074 (don't drop arguments' temporaries in `dbg!`)
 - rust-lang/rust#154328 (rustdoc: add missing {os,target,target_env} values for cfg pretty printer)
 - rust-lang/rust#154540 (Fix invalid type suggestion for item nested in function)
 - rust-lang/rust#154549 (Add regression test for recursive lazy type alias normalization ICE)
 - rust-lang/rust#153373 (Fix LegacyKeyValueFormat report from docker build: powerpc)
 - rust-lang/rust#154322 (feat: reimplement `hash_map!` macro)
 - rust-lang/rust#154416 (Add `IoSplit` diagnostic item for `std::io::Split`)
 - rust-lang/rust#154486 (std_detect on AArch64 Darwin: Detect FEAT_SVE_B16B16)
 - rust-lang/rust#154508 (Fix ambiguous parsing in bootstrap.py)
 - rust-lang/rust#154518 (Panic in Hermit clock_gettime)
 - rust-lang/rust#154530 (update zulip link in `std` documentation)
@m4rch3n1ng m4rch3n1ng deleted the hash-map-macro branch March 31, 2026 16:08
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants