proc_macro_error2/imp/
fallback.rs

1//! This implementation uses self-written stable facilities.
2
3use crate::{
4    abort_now, check_correctness,
5    diagnostic::{Diagnostic, Level},
6};
7use std::cell::RefCell;
8
9pub fn abort_if_dirty() {
10    check_correctness();
11    ERR_STORAGE.with(|storage| {
12        if !storage.borrow().is_empty() {
13            abort_now()
14        }
15    });
16}
17
18pub(crate) fn cleanup() -> Vec<Diagnostic> {
19    ERR_STORAGE.with(|storage| storage.replace(Vec::new()))
20}
21
22pub(crate) fn emit_diagnostic(diag: Diagnostic) {
23    if diag.level == Level::Error {
24        ERR_STORAGE.with(|storage| storage.borrow_mut().push(diag));
25    }
26}
27
28thread_local! {
29    static ERR_STORAGE: RefCell<Vec<Diagnostic>> = const { RefCell::new(Vec::new()) };
30}