Add memory fence tests for invalid_atomic_ordering

This commit is contained in:
Krishna Sai Veera Reddy 2020-01-09 09:51:13 -08:00
parent e2e40f2570
commit 5e058f38f4
2 changed files with 39 additions and 0 deletions

View File

@ -0,0 +1,20 @@
#![warn(clippy::invalid_atomic_ordering)]
use std::sync::atomic::{compiler_fence, fence, Ordering};
fn main() {
// Allowed fence ordering modes
fence(Ordering::Acquire);
fence(Ordering::Release);
fence(Ordering::AcqRel);
fence(Ordering::SeqCst);
// Disallowed fence ordering modes
fence(Ordering::Relaxed);
compiler_fence(Ordering::Acquire);
compiler_fence(Ordering::Release);
compiler_fence(Ordering::AcqRel);
compiler_fence(Ordering::SeqCst);
compiler_fence(Ordering::Relaxed);
}

View File

@ -0,0 +1,19 @@
error: memory fences cannot have `Relaxed` ordering
--> $DIR/atomic_ordering_fence.rs:13:11
|
LL | fence(Ordering::Relaxed);
| ^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
= help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`
error: memory fences cannot have `Relaxed` ordering
--> $DIR/atomic_ordering_fence.rs:19:20
|
LL | compiler_fence(Ordering::Relaxed);
| ^^^^^^^^^^^^^^^^^
|
= help: consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`
error: aborting due to 2 previous errors