rustc_lint::types

Static INVALID_ATOMIC_ORDERING

Source
static INVALID_ATOMIC_ORDERING: &Lint
Expand description

The invalid_atomic_ordering lint detects passing an Ordering to an atomic operation that does not support that ordering.

§Example

let atom = AtomicU8::new(0);
let value = atom.load(Ordering::Release);

{{produces}}

§Explanation

Some atomic operations are only supported for a subset of the atomic::Ordering variants. Passing an unsupported variant will cause an unconditional panic at runtime, which is detected by this lint.

This lint will trigger in the following cases: (where AtomicType is an atomic type from core::sync::atomic, such as AtomicBool, AtomicPtr, AtomicUsize, or any of the other integer atomics).

  • Passing Ordering::Acquire or Ordering::AcqRel to AtomicType::store.

  • Passing Ordering::Release or Ordering::AcqRel to AtomicType::load.

  • Passing Ordering::Relaxed to core::sync::atomic::fence or core::sync::atomic::compiler_fence.

  • Passing Ordering::Release or Ordering::AcqRel as the failure ordering for any of AtomicType::compare_exchange, AtomicType::compare_exchange_weak, or AtomicType::fetch_update.