Merge pull request #3589 from topecongiro/issue-3583
Catch panics from the parser while rewriting macro calls
This commit is contained in:
commit
1c210eb3c6
3 changed files with 16 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -475,3 +475,6 @@ pub fn fold_abi<V: Fold + ?Sized>(_visitor: &mut V, _i: Abi) -> Abi {
|
|||
// #3463
|
||||
x ! {()}
|
||||
x ! y {()}
|
||||
|
||||
// #3583
|
||||
foo!(|x = y|);
|
||||
|
|
|
|||
|
|
@ -1052,3 +1052,6 @@ pub fn fold_abi<V: Fold + ?Sized>(_visitor: &mut V, _i: Abi) -> Abi {
|
|||
// #3463
|
||||
x! {()}
|
||||
x! y {()}
|
||||
|
||||
// #3583
|
||||
foo!(|x = y|);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue