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

Hashmap section on const/static construction should mention LazyLock as a way to resolve problems mentioned. #137566

Closed
burtonageo opened this issue Feb 24, 2025 · 1 comment · Fixed by #137870
Assignees
Labels
A-collections Area: `std::collections` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@burtonageo
Copy link
Contributor

burtonageo commented Feb 24, 2025

Location

https://doc.rust-lang.org/stable/std/collections/struct.HashMap.html#usage-in-const-and-static

Summary

In the documentation for HashMap, the section on using it in a static/const context mentions that a const seed should be used. However, using a LazyLock<> to wrap the HashMap allows it to be constructed with a random seed, which resolves the main problem highlighted at the end of the paragraph.

LazyLock has been stabilized as of rust 1.80

@burtonageo burtonageo added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Feb 24, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 24, 2025
@lolbinarycat lolbinarycat added A-collections Area: `std::collections` T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 24, 2025
@Noratrieb Noratrieb added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 1, 2025
@karolzwolak
Copy link
Contributor

@rustbot claim

@bors bors closed this as completed in 936e51e Mar 14, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 14, 2025
Rollup merge of rust-lang#137870 - karolzwolak:lazylock-const-hashmaps-137566, r=cuviper

 Improve HashMap docs for const and static initializers

Closes rust-lang#137566.
I clarified the HashMap usage in const and static initializers.
I also added examples of how to construct such HashMaps wrapped in LazyLock.
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Mar 19, 2025
…s-137566, r=cuviper

 Improve HashMap docs for const and static initializers

Closes rust-lang#137566.
I clarified the HashMap usage in const and static initializers.
I also added examples of how to construct such HashMaps wrapped in LazyLock.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collections` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants