Set the flag in RewriteContext when rewriting macro call failed
This commit is contained in:
parent
5e59e686c1
commit
94e68b1eb6
@ -129,6 +129,12 @@ fn rewrite_macro_name(path: &ast::Path, extra_ident: Option<ast::Ident>) -> Stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use this on failing to format the macro call.
|
||||||
|
fn return_original_snippet_with_failure_marked(context: &RewriteContext, span: Span) -> Option<String> {
|
||||||
|
context.macro_rewrite_failure.replace(true);
|
||||||
|
Some(context.snippet(span).to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn rewrite_macro(
|
pub fn rewrite_macro(
|
||||||
mac: &ast::Mac,
|
mac: &ast::Mac,
|
||||||
extra_ident: Option<ast::Ident>,
|
extra_ident: Option<ast::Ident>,
|
||||||
@ -138,6 +144,9 @@ pub fn rewrite_macro(
|
|||||||
) -> Option<String> {
|
) -> Option<String> {
|
||||||
context.inside_macro.replace(true);
|
context.inside_macro.replace(true);
|
||||||
let result = rewrite_macro_inner(mac, extra_ident, context, shape, position);
|
let result = rewrite_macro_inner(mac, extra_ident, context, shape, position);
|
||||||
|
if result.is_none() {
|
||||||
|
context.macro_rewrite_failure.replace(true);
|
||||||
|
}
|
||||||
context.inside_macro.replace(false);
|
context.inside_macro.replace(false);
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
@ -196,7 +205,7 @@ pub fn rewrite_macro_inner(
|
|||||||
loop {
|
loop {
|
||||||
match parse_macro_arg(&mut parser) {
|
match parse_macro_arg(&mut parser) {
|
||||||
Some(arg) => arg_vec.push(arg),
|
Some(arg) => arg_vec.push(arg),
|
||||||
None => return Some(context.snippet(mac.span).to_owned()),
|
None => return return_original_snippet_with_failure_marked(context, mac.span),
|
||||||
}
|
}
|
||||||
|
|
||||||
match parser.token {
|
match parser.token {
|
||||||
@ -216,13 +225,13 @@ pub fn rewrite_macro_inner(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => return Some(context.snippet(mac.span).to_owned()),
|
None => return return_original_snippet_with_failure_marked(context, mac.span),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Some(context.snippet(mac.span).to_owned());
|
return return_original_snippet_with_failure_marked(context, mac.span);
|
||||||
}
|
}
|
||||||
_ => return Some(context.snippet(mac.span).to_owned()),
|
_ => return return_original_snippet_with_failure_marked(context, mac.span),
|
||||||
}
|
}
|
||||||
|
|
||||||
parser.bump();
|
parser.bump();
|
||||||
|
@ -39,6 +39,8 @@ pub struct RewriteContext<'a> {
|
|||||||
// When rewriting chain, veto going multi line except the last element
|
// When rewriting chain, veto going multi line except the last element
|
||||||
pub force_one_line_chain: RefCell<bool>,
|
pub force_one_line_chain: RefCell<bool>,
|
||||||
pub snippet_provider: &'a SnippetProvider<'a>,
|
pub snippet_provider: &'a SnippetProvider<'a>,
|
||||||
|
// Used for `format_snippet`
|
||||||
|
pub(crate) macro_rewrite_failure: RefCell<bool>,
|
||||||
pub(crate) report: FormatReport,
|
pub(crate) report: FormatReport,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user