summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/lint-invalid-atomic-ordering-fetch-update.rs
blob: 734b63324af257c56148a6c490a703fc9217c8e1 (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
// only-x86_64
use std::sync::atomic::{AtomicIsize, Ordering};

fn main() {
    // `fetch_update` testing
    let x = AtomicIsize::new(0);

    // Allowed ordering combos
    let _ = x.fetch_update(Ordering::Relaxed, Ordering::Relaxed, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Relaxed, Ordering::Acquire, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Relaxed, Ordering::SeqCst, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Acquire, Ordering::Relaxed, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Acquire, Ordering::Acquire, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Acquire, Ordering::SeqCst, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Release, Ordering::Relaxed, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Release, Ordering::Acquire, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::Release, Ordering::SeqCst, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::AcqRel, Ordering::Relaxed, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::AcqRel, Ordering::Acquire, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::AcqRel, Ordering::SeqCst, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::SeqCst, Ordering::Relaxed, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::SeqCst, Ordering::Acquire, |old| Some(old + 1));
    let _ = x.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |old| Some(old + 1));

    // AcqRel is always forbidden as a failure ordering
    let _ = x.fetch_update(Ordering::Relaxed, Ordering::AcqRel, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::Acquire, Ordering::AcqRel, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::Release, Ordering::AcqRel, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::AcqRel, Ordering::AcqRel, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::SeqCst, Ordering::AcqRel, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`

    // Release is always forbidden as a failure ordering
    let _ = x.fetch_update(Ordering::Relaxed, Ordering::Release, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::Acquire, Ordering::Release, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::Release, Ordering::Release, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::AcqRel, Ordering::Release, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`
    let _ = x.fetch_update(Ordering::SeqCst, Ordering::Release, |old| Some(old + 1));
    //~^ ERROR `fetch_update`'s failure ordering may not be `Release` or `AcqRel`

}