Open
Description
I just got caught by a footgun where I'd declared a global counter as:
const COUNTER: AtomicUsize = AtomicUsize::new(0);
and incremented it using COUNTER.fetch_add(1, Ordering::SeqCst)
. It took me a while to realize why I was always getting 0
! There are checks for const
declarations not having interior mutability to catch these footguns, but they don't apply to atomics.
Metadata
Metadata
Assignees
Labels
Area: Atomics, barriers, and sync primitivesArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Lints (warnings about flaws in source code) such as unused_mut.Category: An issue proposing an enhancement or a PR with one.Relevant to the compiler team, which will review and decide on the PR/issue.Relevant to the language team, which will review and decide on the PR/issue.