rust/tests/ui/atomic_ordering_bool.rs

26 lines
678 B
Rust
Raw Normal View History

2020-01-06 01:52:15 +01:00
#![warn(clippy::invalid_atomic_ordering)]
use std::sync::atomic::{AtomicBool, Ordering};
fn main() {
let x = AtomicBool::new(true);
// Allowed load ordering modes
let _ = x.load(Ordering::Acquire);
let _ = x.load(Ordering::SeqCst);
let _ = x.load(Ordering::Relaxed);
// Disallowed load ordering modes
let _ = x.load(Ordering::Release);
let _ = x.load(Ordering::AcqRel);
// Allowed store ordering modes
x.store(false, Ordering::Release);
x.store(false, Ordering::SeqCst);
x.store(false, Ordering::Relaxed);
// Disallowed store ordering modes
x.store(false, Ordering::Acquire);
x.store(false, Ordering::AcqRel);
}