From 36dd49ae5f4fd0e0d54111533f1577fccfef979a Mon Sep 17 00:00:00 2001 From: topecongiro Date: Tue, 28 May 2019 00:14:36 +0900 Subject: [PATCH] Set macro_rewrite_failure to true on catching panic --- src/macros.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index d25106c49616..077e6a32d62c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -209,24 +209,25 @@ pub(crate) fn rewrite_macro( shape: Shape, position: MacroPosition, ) -> Option { - catch_unwind(AssertUnwindSafe(|| { - let should_skip = context - .skip_macro_names - .borrow() - .contains(&context.snippet(mac.node.path.span).to_owned()); - if should_skip { - None - } else { - let guard = InsideMacroGuard::inside_macro_context(context); - let result = - rewrite_macro_inner(mac, extra_ident, context, shape, position, guard.is_nested); - if result.is_none() { + let should_skip = context + .skip_macro_names + .borrow() + .contains(&context.snippet(mac.node.path.span).to_owned()); + if should_skip { + None + } else { + let guard = InsideMacroGuard::inside_macro_context(context); + let result = catch_unwind(AssertUnwindSafe(|| { + rewrite_macro_inner(mac, extra_ident, context, shape, position, guard.is_nested) + })); + match result { + Err(..) | Ok(None) => { context.macro_rewrite_failure.replace(true); + None } - result + Ok(rw) => rw, } - })) - .ok()? + } } fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option {