Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 49568d7

Browse files
committed
Do not modify original source code inside macro call
1 parent 30cda58 commit 49568d7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/closures.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn rewrite_closure(
5959
}
6060

6161
let result = match fn_decl.output {
62-
ast::FunctionRetTy::Default(_) => {
62+
ast::FunctionRetTy::Default(_) if !context.inside_macro() => {
6363
try_rewrite_without_block(body, &prefix, context, shape, body_shape)
6464
}
6565
_ => None,
@@ -306,6 +306,7 @@ pub fn rewrite_last_closure(
306306
let body = match body.node {
307307
ast::ExprKind::Block(ref block, _)
308308
if !is_unsafe_block(block)
309+
&& !context.inside_macro()
309310
&& is_simple_block(block, Some(&body.attrs), context.source_map) =>
310311
{
311312
stmt_expr(&block.stmts[0]).unwrap_or(body)

src/types.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,13 @@ impl Rewrite for ast::Ty {
583583
let is_dyn = tobj_syntax == ast::TraitObjectSyntax::Dyn;
584584
// 4 is length of 'dyn '
585585
let shape = if is_dyn { shape.offset_left(4)? } else { shape };
586-
let res = bounds.rewrite(context, shape)?;
586+
let mut res = bounds.rewrite(context, shape)?;
587+
// We may have falsely removed a trailing `+` inside macro call.
588+
if context.inside_macro() && bounds.len() == 1 {
589+
if context.snippet(self.span).ends_with('+') && !res.ends_with('+') {
590+
res.push('+');
591+
}
592+
}
587593
if is_dyn {
588594
Some(format!("dyn {}", res))
589595
} else {

0 commit comments

Comments
 (0)