]> git.proxmox.com Git - rustc.git/blob - vendor/proc-macro-error/src/imp/fallback.rs
New upstream version 1.71.1+dfsg1
[rustc.git] / vendor / proc-macro-error / src / imp / fallback.rs
1 //! This implementation uses self-written stable facilities.
2
3 use crate::{
4 abort_now, check_correctness,
5 diagnostic::{Diagnostic, Level},
6 };
7 use std::cell::RefCell;
8
9 pub 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
18 pub(crate) fn cleanup() -> Vec<Diagnostic> {
19 ERR_STORAGE.with(|storage| storage.replace(Vec::new()))
20 }
21
22 pub(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
28 thread_local! {
29 static ERR_STORAGE: RefCell<Vec<Diagnostic>> = RefCell::new(Vec::new());
30 }