Merge pull request #3589 from topecongiro/issue-3583

Catch panics from the parser while rewriting macro calls
This commit is contained in:
Stéphane Campinas 2019-05-28 00:49:28 +02:00 committed by GitHub
commit 1c210eb3c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 5 deletions

View file

@ -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
}
}

View file

@ -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|);

View file

@ -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|);