Skip to content

Commit 4411903

Browse files
committed
Add a scheme for registering and obtaining errors even without access to an InterpCx
1 parent 4de031b commit 4411903

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/diagnostics.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,20 @@ pub fn report_err<'tcx, 'mir>(
6060
// Let the reported error determine the return code.
6161
return None;
6262
}
63+
64+
use std::cell::RefCell;
65+
thread_local! {
66+
static ECX: RefCell<Vec<InterpErrorInfo<'static>>> = RefCell::new(Vec::new());
67+
}
68+
69+
pub fn register_err(e: InterpErrorInfo<'static>) {
70+
ECX.with(|ecx| ecx.borrow_mut().push(e));
71+
}
72+
73+
pub fn process_errors(mut f: impl FnMut(InterpErrorInfo<'static>)) {
74+
ECX.with(|ecx| {
75+
for e in ecx.borrow_mut().drain(..) {
76+
f(e);
77+
}
78+
});
79+
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub use crate::shims::time::EvalContextExt as TimeEvalContextExt;
4242
pub use crate::shims::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
4343
pub use crate::shims::EvalContextExt as ShimsEvalContextExt;
4444

45-
pub use crate::diagnostics::report_err;
45+
pub use crate::diagnostics::{process_errors, register_err, report_err};
4646
pub use crate::eval::{create_ecx, eval_main, MiriConfig, TerminationInfo};
4747
pub use crate::helpers::EvalContextExt as HelpersEvalContextExt;
4848
pub use crate::machine::{

0 commit comments

Comments
 (0)