Catch panics from the parser while rewriting macro calls
// 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;
@@ -208,6 +209,7 @@ pub(crate) fn rewrite_macro(
shape: Shape,
position: MacroPosition,
) -> Option<String> {
+ catch_unwind(AssertUnwindSafe(|| {
let should_skip = context
.skip_macro_names
.borrow()
@@ -223,6 +225,8 @@ pub(crate) fn rewrite_macro(
}
result
}
+ }))
+ .ok()?
}
fn check_keyword<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
