crftng-intrprtrs/gc/src/test_utils.rs

29 lines
560 B
Rust

use std::sync::atomic::{AtomicBool, Ordering};
use crate::trace::GCTrace;
#[derive(Default)]
pub struct GotDropped(AtomicBool);
impl GotDropped {
pub fn make_drop_checker(&self) -> DropChecker {
DropChecker(self)
}
pub fn was_dropped(&self) -> bool {
self.0.load(Ordering::SeqCst)
}
}
pub struct DropChecker<'a>(pub &'a GotDropped);
impl<'a> Drop for DropChecker<'a> {
fn drop(&mut self) {
self.0 .0.store(true, Ordering::SeqCst);
}
}
unsafe impl<'a> GCTrace for DropChecker<'a> {
fn trace(&self, _tracer: &mut crate::trace::GCTracer) {}
}