Do not modify original source code inside macro call
This commit is contained in:
parent
30cda580bd
commit
49568d7f76
2 changed files with 9 additions and 2 deletions
|
@ -59,7 +59,7 @@ pub fn rewrite_closure(
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = match fn_decl.output {
|
let result = match fn_decl.output {
|
||||||
ast::FunctionRetTy::Default(_) => {
|
ast::FunctionRetTy::Default(_) if !context.inside_macro() => {
|
||||||
try_rewrite_without_block(body, &prefix, context, shape, body_shape)
|
try_rewrite_without_block(body, &prefix, context, shape, body_shape)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -306,6 +306,7 @@ pub fn rewrite_last_closure(
|
||||||
let body = match body.node {
|
let body = match body.node {
|
||||||
ast::ExprKind::Block(ref block, _)
|
ast::ExprKind::Block(ref block, _)
|
||||||
if !is_unsafe_block(block)
|
if !is_unsafe_block(block)
|
||||||
|
&& !context.inside_macro()
|
||||||
&& is_simple_block(block, Some(&body.attrs), context.source_map) =>
|
&& is_simple_block(block, Some(&body.attrs), context.source_map) =>
|
||||||
{
|
{
|
||||||
stmt_expr(&block.stmts[0]).unwrap_or(body)
|
stmt_expr(&block.stmts[0]).unwrap_or(body)
|
||||||
|
|
|
@ -583,7 +583,13 @@ impl Rewrite for ast::Ty {
|
||||||
let is_dyn = tobj_syntax == ast::TraitObjectSyntax::Dyn;
|
let is_dyn = tobj_syntax == ast::TraitObjectSyntax::Dyn;
|
||||||
// 4 is length of 'dyn '
|
// 4 is length of 'dyn '
|
||||||
let shape = if is_dyn { shape.offset_left(4)? } else { shape };
|
let shape = if is_dyn { shape.offset_left(4)? } else { shape };
|
||||||
let res = bounds.rewrite(context, shape)?;
|
let mut res = bounds.rewrite(context, shape)?;
|
||||||
|
// We may have falsely removed a trailing `+` inside macro call.
|
||||||
|
if context.inside_macro() && bounds.len() == 1 {
|
||||||
|
if context.snippet(self.span).ends_with('+') && !res.ends_with('+') {
|
||||||
|
res.push('+');
|
||||||
|
}
|
||||||
|
}
|
||||||
if is_dyn {
|
if is_dyn {
|
||||||
Some(format!("dyn {}", res))
|
Some(format!("dyn {}", res))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue