use crate::{check_correctness, AbortNow, MacroError};
use std::cell::RefCell;
thread_local! {
static ERR_STORAGE: RefCell<Vec<MacroError>> = RefCell::new(Vec::new());
}
#[macro_export]
macro_rules! emit_error {
($($tts:tt)*) => {{
$crate::macro_error!($($tts)*).emit()
}};
}
#[macro_export]
macro_rules! emit_call_site_error {
($($tts:tt)*) => {{
let span = $crate::proc_macro2::Span::call_site();
$crate::macro_error!(span, $($tts)*).emit()
}};
}
pub fn abort_if_dirty() {
check_correctness();
ERR_STORAGE.with(|storage| {
if !storage.borrow().is_empty() {
abort_now()
}
});
}
pub(crate) fn cleanup() -> Vec<MacroError> {
ERR_STORAGE.with(|storage| storage.replace(Vec::new()))
}
pub(crate) fn abort_now() -> ! {
check_correctness();
panic!(AbortNow)
}
#[doc(hidden)]
pub fn push_error(error: MacroError) {
check_correctness();
ERR_STORAGE.with(|storage| storage.borrow_mut().push(error))
}