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
18 pub struct NonFatal(pub String);
20 /// Use when something in the current function is unimplemented.
22 /// This will emit an error and continue codegen at a different function.
23 pub macro unimpl($($tt:tt)*) {
24 panic!(NonFatal(format!($($tt)*)));
27 pub fn try_unimpl(tcx: TyCtxt, log: &mut Option<File>, f: impl FnOnce()) {
28 let res = ::std::panic::catch_unwind(::std::panic::AssertUnwindSafe(|| f()));
30 if let Err(err) = res {
31 SPAN_STACK.with(|span_stack| {
32 match err.downcast::<NonFatal>() {
34 if cfg!(debug_assertions) {
36 log.as_mut().unwrap(),
43 tcx.sess.err(&non_fatal.0)
45 Err(err) => ::std::panic::resume_unwind(err),
47 span_stack.borrow_mut().clear();
52 pub fn with_unimpl_span(span: Span, f: impl FnOnce()) {
53 SPAN_STACK.with(|span_stack| {
54 span_stack.borrow_mut().push(span);
56 span_stack.borrow_mut().pop();