-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
std::sync::Once::call_once executes closure multiple times when create as const #93464
Comments
This is because each use of We may want to consider uplifting Clippy's lint against consts with interior mutability. |
A simpler example is a |
Along with a lint it might be also helpful to add some note in docs for |
They const keyword docs mention this. https://doc.rust-lang.org/std/keyword.const.html
|
I'll note that the very first example on the static START: Once = Once::new(); Which is a pretty strong encouragement to use |
Duplicate of #40543? |
Closing this as duplicate of #40543 |
I tried this code:
I expected to see an output:
Instead, the output:
The code starts to works as expected once
const INIT
is replaced bystatic INIT
.It can be reproduced on rust playground either on stable/betta/nightly builds.
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: