mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Add memory fence tests for invalid_atomic_ordering
This commit is contained in:
parent
e2e40f2570
commit
5e058f38f4
2 changed files with 39 additions and 0 deletions
20
tests/ui/atomic_ordering_fence.rs
Normal file
20
tests/ui/atomic_ordering_fence.rs
Normal 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);
|
||||
}
|
19
tests/ui/atomic_ordering_fence.stderr
Normal file
19
tests/ui/atomic_ordering_fence.stderr
Normal 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
|
||||
|
Loading…
Reference in a new issue