diff --git a/src/macros.rs b/src/macros.rs index a42b839f9c50..077e6a32d62c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -10,6 +10,7 @@ // and those with brackets will be formatted as array literals. use std::collections::HashMap; +use std::panic::{catch_unwind, AssertUnwindSafe}; use syntax::parse::new_parser_from_tts; use syntax::parse::parser::Parser; @@ -216,12 +217,16 @@ pub(crate) fn rewrite_macro( 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() { - context.macro_rewrite_failure.replace(true); + 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 + } + Ok(rw) => rw, } - result } } diff --git a/tests/source/macros.rs b/tests/source/macros.rs index 66012e4d69d4..ef5b1efa5b96 100644 --- a/tests/source/macros.rs +++ b/tests/source/macros.rs @@ -475,3 +475,6 @@ pub fn fold_abi(_visitor: &mut V, _i: Abi) -> Abi { // #3463 x ! {()} x ! y {()} + +// #3583 +foo!(|x = y|); diff --git a/tests/target/macros.rs b/tests/target/macros.rs index 8f86b79f9225..f19b5d11feef 100644 --- a/tests/target/macros.rs +++ b/tests/target/macros.rs @@ -1052,3 +1052,6 @@ pub fn fold_abi(_visitor: &mut V, _i: Abi) -> Abi { // #3463 x! {()} x! y {()} + +// #3583 +foo!(|x = y|);