Skip to content

feat: reimplement hash_map! macro#154322

Open
m4rch3n1ng wants to merge 1 commit intorust-lang:mainfrom
m4rch3n1ng:hash-map-macro
Open

feat: reimplement hash_map! macro#154322
m4rch3n1ng wants to merge 1 commit intorust-lang:mainfrom
m4rch3n1ng:hash-map-macro

Conversation

@m4rch3n1ng
Copy link
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
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
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
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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants