mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
Separate compare_exchange and compare_exchange_weak uitests
This commit is contained in:
parent
61671a2268
commit
159178e5d4
4 changed files with 179 additions and 168 deletions
|
@ -42,43 +42,4 @@ fn main() {
|
|||
// Acquire/AcqRel forbids failure order of SeqCst
|
||||
let _ = x.compare_exchange(0, 0, Ordering::Acquire, Ordering::SeqCst);
|
||||
let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst);
|
||||
|
||||
// compare_exchange_weak tests
|
||||
|
||||
// Allowed ordering combos
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::SeqCst, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::SeqCst, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::SeqCst, Ordering::SeqCst);
|
||||
|
||||
// AcqRel is always forbidden as a failure ordering
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::SeqCst, Ordering::AcqRel);
|
||||
|
||||
// Release is always forbidden as a failure ordering
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::SeqCst, Ordering::Release);
|
||||
|
||||
// Release success order forbids failure order of Acquire or SeqCst
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::SeqCst);
|
||||
|
||||
// Relaxed success order also forbids failure order of Acquire or SeqCst
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::SeqCst);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::Acquire);
|
||||
|
||||
// Acquire/AcqRel forbids failure order of SeqCst
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::SeqCst);
|
||||
let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::SeqCst);
|
||||
}
|
||||
|
|
|
@ -127,133 +127,5 @@ LL | let _ = x.compare_exchange(0, 0, Ordering::AcqRel, Ordering::SeqCst);
|
|||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:60:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:61:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:62:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:63:61
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:64:61
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::SeqCst, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:67:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:68:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:69:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:70:61
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:71:61
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::SeqCst, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Release`
|
||||
--> $DIR/atomic_ordering_exchange.rs:74:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::Acquire);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Release`
|
||||
--> $DIR/atomic_ordering_exchange.rs:75:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Release, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Relaxed`
|
||||
--> $DIR/atomic_ordering_exchange.rs:78:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Relaxed`
|
||||
--> $DIR/atomic_ordering_exchange.rs:79:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Relaxed, Ordering::Acquire);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Acquire`
|
||||
--> $DIR/atomic_ordering_exchange.rs:82:62
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::Acquire, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange.rs:83:61
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(0, 0, Ordering::AcqRel, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: aborting due to 32 previous errors
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
47
tests/ui/atomic_ordering_exchange_weak.rs
Normal file
47
tests/ui/atomic_ordering_exchange_weak.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
#![warn(clippy::invalid_atomic_ordering)]
|
||||
|
||||
use std::sync::atomic::{AtomicPtr, Ordering};
|
||||
|
||||
fn main() {
|
||||
let ptr = &mut 5;
|
||||
let ptr2 = &mut 10;
|
||||
// `compare_exchange_weak` testing
|
||||
let x = AtomicPtr::new(ptr);
|
||||
|
||||
// Allowed ordering combos
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Relaxed);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::SeqCst);
|
||||
|
||||
// AcqRel is always forbidden as a failure ordering
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel);
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel);
|
||||
|
||||
// Release is always forbidden as a failure ordering
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release);
|
||||
|
||||
// Release success order forbids failure order of Acquire or SeqCst
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire);
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst);
|
||||
|
||||
// Relaxed success order also forbids failure order of Acquire or SeqCst
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst);
|
||||
let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire);
|
||||
|
||||
// Acquire/AcqRel forbids failure order of SeqCst
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst);
|
||||
let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst);
|
||||
}
|
131
tests/ui/atomic_ordering_exchange_weak.stderr
Normal file
131
tests/ui/atomic_ordering_exchange_weak.stderr
Normal file
|
@ -0,0 +1,131 @@
|
|||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:23:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Relaxed, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D clippy::invalid-atomic-ordering` implied by `-D warnings`
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:24:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:25:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:26:66
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:27:66
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:30:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:31:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:32:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:33:66
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not be `Release` or `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:34:66
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire`, `SeqCst` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Release`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:37:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Release`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:38:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Relaxed`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:41:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Relaxed`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:42:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Acquire);
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering mode `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `Acquire`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:45:67
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: compare_exchange_weak's failure ordering may not stronger than the success ordering of `AcqRel`
|
||||
--> $DIR/atomic_ordering_exchange_weak.rs:46:66
|
||||
|
|
||||
LL | let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst);
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider using ordering modes `Acquire` or `Relaxed` instead
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
Loading…
Reference in a new issue