1 //! The unimpl! macro is defined here. It is used to generate
2 //! a non-fatal error on not yet implemented things.
4 use std::cell::RefCell;
8 use syntax::source_map::Span;
10 use rustc::ty::TyCtxt;
13 static SPAN_STACK: RefCell<Vec<Span>> = RefCell::new(vec![]);
16 // Just public, because of the unimpl macro
17 pub struct NonFatal(pub String);
19 pub macro unimpl($($tt:tt)*) {
20 panic!(NonFatal(format!($($tt)*)));
23 pub fn try_unimpl(tcx: TyCtxt, log: &mut Option<File>, f: impl FnOnce()) {
24 let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| f()));
26 if let Err(err) = res {
27 SPAN_STACK.with(|span_stack| {
28 match err.downcast::<NonFatal>() {
30 if cfg!(debug_assertions) {
32 log.as_mut().unwrap(),
39 tcx.sess.err(&non_fatal.0)
41 Err(err) => ::std::panic::resume_unwind(err),
43 span_stack.borrow_mut().clear();
48 pub fn with_unimpl_span(span: Span, f: impl FnOnce()) {
49 SPAN_STACK.with(|span_stack| {
50 span_stack.borrow_mut().push(span);
52 span_stack.borrow_mut().pop();