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

Open
burtonageo opened this issue Feb 24, 2025 · 0 comments
Labels
A-collections Area: `std::collections` A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@burtonageo
Copy link
Contributor

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
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 needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants