#[cfg(debug_assertions)]
#[allow(dead_code)] #[derive(Copy, Clone)]
pub(crate) struct AccessDiagnostics {
pub defined_at: &'static std::panic::Location<'static>,
pub called_at: &'static std::panic::Location<'static>,
}
#[cfg(not(debug_assertions))]
#[derive(Copy, Clone, Default)]
pub(crate) struct AccessDiagnostics {}
#[doc(hidden)]
pub struct SpecialNonReactiveZone {}
cfg_if::cfg_if! {
if #[cfg(debug_assertions)] {
use std::cell::Cell;
thread_local! {
static IS_SPECIAL_ZONE: Cell<bool> = const { Cell::new(false) };
}
}
}
impl SpecialNonReactiveZone {
#[allow(dead_code)] #[inline(always)]
pub(crate) fn is_inside() -> bool {
#[cfg(debug_assertions)]
{
IS_SPECIAL_ZONE.with(|val| val.get())
}
#[cfg(not(debug_assertions))]
false
}
#[cfg(debug_assertions)]
pub fn enter() -> bool {
IS_SPECIAL_ZONE.with(|val| {
let prev = val.get();
val.set(true);
prev
})
}
#[cfg(debug_assertions)]
pub fn exit(prev: bool) {
if !prev {
IS_SPECIAL_ZONE.with(|val| val.set(false))
}
}
}
#[doc(hidden)]
#[macro_export]
macro_rules! diagnostics {
($this:ident) => {{
cfg_if::cfg_if! {
if #[cfg(debug_assertions)] {
AccessDiagnostics {
defined_at: $this.defined_at,
called_at: std::panic::Location::caller()
}
} else {
AccessDiagnostics { }
}
}
}};
}