summaryrefslogtreecommitdiffstats
path: root/tests/ui/consts/issue-90762.rs
blob: 78d387386f8957c2c89996356391aba15b27901e (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
// run-pass
#![allow(unreachable_code)]

use std::sync::atomic::{AtomicBool, Ordering, AtomicUsize};

struct Print(usize);

impl Drop for Print {
    fn drop(&mut self) {
        println!("{}", self.0);
        FOO[self.0].store(true, Ordering::Relaxed);
        assert_eq!(BAR.fetch_sub(1, Ordering::Relaxed), self.0);
    }
}

const A: Print = Print(0);
const B: Print = Print(1);

static FOO: [AtomicBool; 3] =
    [AtomicBool::new(false), AtomicBool::new(false), AtomicBool::new(false)];
static BAR: AtomicUsize = AtomicUsize::new(2);

fn main() {
    loop {
        std::mem::forget(({ A }, B, Print(2), break));
    }
    for (i, b) in FOO.iter().enumerate() {
        assert!(b.load(Ordering::Relaxed), "{} not set", i);
    }
    assert_eq!(BAR.fetch_add(1, Ordering::Relaxed), usize::max_value());
}