Open
Description
I tried this code playground link:
use std::sync::Once;
const INIT: Once = Once::new();
fn main() {
INIT.call_once(|| {
println!("Global Once::call_once first call");
});
INIT.call_once(|| {
println!("Global Once::call_once second call");
});
}
The problem is that my Once is in a const
and not a static
. However, I would expect a compile error or a runtime error instead of broken behavior here. The same behavior is exhibited in std::sync::LazyLock
and probably std::sync::OnceLock
, due to using a Once internally.
Thanks for considering this!
Meta
Checked on 1.82.0 and on nightly.