-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
clubby789, algebnaly, ebkalderon, stanislav-tkach, Bromeon and 1 more
Metadata
Metadata
Assignees
Labels
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.