xref: /third_party/rust/crates/proc-macro-error/src/imp/fallback.rs
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/rust/crates/proc-macro-error/src/imp/
1ea88969fSopenharmony_ci//! This implementation uses self-written stable facilities.
2ea88969fSopenharmony_ci
3ea88969fSopenharmony_ciuse crate::{
4ea88969fSopenharmony_ci    abort_now, check_correctness,
5ea88969fSopenharmony_ci    diagnostic::{Diagnostic, Level},
6ea88969fSopenharmony_ci};
7ea88969fSopenharmony_ciuse std::cell::RefCell;
8ea88969fSopenharmony_ci
9ea88969fSopenharmony_cipub fn abort_if_dirty() {
10ea88969fSopenharmony_ci    check_correctness();
11ea88969fSopenharmony_ci    ERR_STORAGE.with(|storage| {
12ea88969fSopenharmony_ci        if !storage.borrow().is_empty() {
13ea88969fSopenharmony_ci            abort_now()
14ea88969fSopenharmony_ci        }
15ea88969fSopenharmony_ci    });
16ea88969fSopenharmony_ci}
17ea88969fSopenharmony_ci
18ea88969fSopenharmony_cipub(crate) fn cleanup() -> Vec<Diagnostic> {
19ea88969fSopenharmony_ci    ERR_STORAGE.with(|storage| storage.replace(Vec::new()))
20ea88969fSopenharmony_ci}
21ea88969fSopenharmony_ci
22ea88969fSopenharmony_cipub(crate) fn emit_diagnostic(diag: Diagnostic) {
23ea88969fSopenharmony_ci    if diag.level == Level::Error {
24ea88969fSopenharmony_ci        ERR_STORAGE.with(|storage| storage.borrow_mut().push(diag));
25ea88969fSopenharmony_ci    }
26ea88969fSopenharmony_ci}
27ea88969fSopenharmony_ci
28ea88969fSopenharmony_cithread_local! {
29ea88969fSopenharmony_ci    static ERR_STORAGE: RefCell<Vec<Diagnostic>> = RefCell::new(Vec::new());
30ea88969fSopenharmony_ci}
31

Indexes created Thu Nov 07 10:32:03 CST 2024