rust/tests/ui/consts/issue-90762.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

32 lines
809 B
Rust
Raw Normal View History

2022-03-09 15:27:28 +00:00
// run-pass
#![allow(unreachable_code)]
use std::sync::atomic::{AtomicBool, Ordering, AtomicUsize};
2022-03-09 15:27:28 +00:00
struct Print(usize);
impl Drop for Print {
fn drop(&mut self) {
println!("{}", self.0);
2022-03-09 15:27:28 +00:00
FOO[self.0].store(true, Ordering::Relaxed);
assert_eq!(BAR.fetch_sub(1, Ordering::Relaxed), self.0);
2022-03-09 15:27:28 +00:00
}
}
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);
2022-03-09 15:27:28 +00:00
fn main() {
loop {
std::mem::forget(({ A }, B, Print(2), break));
2022-03-09 15:27:28 +00:00
}
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());
}