-
Notifications
You must be signed in to change notification settings - Fork 13.3k
LazyLock not working as expected with deref #140340
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
Comments
It’s because |
#132146 adds this as a lint to rustc as well |
I don't get why doesn't const have a static lifetime? This makes the static more const than const itself? |
A const behaves similarly to if you copy-pasted the code into each point you use the const. Your code is roughly equivalent to this: pub fn main() {
info!("{:?} {:?}", *LazyLock::new(|| Uuid::new_v4()), *LazyLock::new(|| Uuid::new_v4()));
} |
Ok thanks for the explanation, maybe const fields can be better implemented similarly like static to prevent side effects. I guess const also have some benefits over static, shall I close the ticket? |
jup, I think this is sufficiently tracked by #132146 |
I'm not sure if this is a bug inside uuid or LazyLock, but I believe LazyLock should prevent any changes without the lock being acquired.
I tried this code:
I expected to see this happen:
Two similar UUID's
Instead, this happened:
[2025-04-26T15:38:56Z INFO splittable_be::templates] 3b9bd2f5-c2e1-433b-962e-1f662acdf5b1 c6258c4c-5bec-4ad5-a5f9-0818ec13537c
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: