summaryrefslogtreecommitdiffstats
path: root/src/test/ui/lint/lint-invalid-atomic-ordering-exchange-weak.rs
blob: 63204c725c3dc27e035c4ecba032ec83708d18c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// only-x86_64
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::Relaxed, Ordering::Acquire);
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::SeqCst);
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Relaxed);
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Acquire);
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::SeqCst);
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Relaxed);
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::Acquire);
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::SeqCst);
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Relaxed);
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Acquire);
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::SeqCst);
    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);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Acquire, Ordering::AcqRel);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::Release, Ordering::AcqRel);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::AcqRel, Ordering::AcqRel);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr2, ptr, Ordering::SeqCst, Ordering::AcqRel);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`

    // Release is always forbidden as a failure ordering
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Relaxed, Ordering::Release);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Acquire, Ordering::Release);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::Release, Ordering::Release);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::AcqRel, Ordering::Release);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.compare_exchange_weak(ptr, ptr2, Ordering::SeqCst, Ordering::Release);
    //~^ ERROR `compare_exchange_weak`'s failure ordering may not be `Release` or `AcqRel`
}