• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
abort_if_dirty()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 
cleanup() -> Vec<Diagnostic>18 pub(crate) fn cleanup() -> Vec<Diagnostic> {
19     ERR_STORAGE.with(|storage| storage.replace(Vec::new()))
20 }
21 
emit_diagnostic(diag: Diagnostic)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 }
31