Skip to content

Commit

Permalink
Don't remove round brackets inside macro calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Glusker authored and rscprof committed Apr 9, 2024
1 parent 7289391 commit c67a2bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,17 @@ fn join_bounds_inner(
_ => false,
};

// We have to restore round brackets inside macro calls
let surrounded_round_brackets = match trailing_span {
Some(ts) => context
.snippet(ts)
.trim_start()
.chars()
.next()
.is_some_and(|x| x == ')'),
_ => false,
};

let shape = if need_indent && force_newline {
shape
.block_indent(context.config.tab_spaces())
Expand Down Expand Up @@ -1031,11 +1042,16 @@ fn join_bounds_inner(
joiner
};

let bound_str = item.rewrite(context, shape)?;
let bound_str = if context.inside_macro() && surrounded_round_brackets {
"(".to_owned() + &bound_str + ")"
} else {
bound_str
};
let (extendable, trailing_str) = if i == 0 {
let bound_str = item.rewrite(context, shape)?;
(is_bound_extendable(&bound_str, item), bound_str)
} else {
let bound_str = &item.rewrite(context, shape)?;
let bound_str = &bound_str;
match leading_span {
Some(ls) if has_leading_comment => (
is_bound_extendable(bound_str, item),
Expand Down
3 changes: 3 additions & 0 deletions tests/source/issue-5959/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
mymacro!( ( for<'a> Fn() ) + Send + Sync);
}
3 changes: 3 additions & 0 deletions tests/target/issue-5959/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
mymacro!((for<'a> Fn()) + Send + Sync);
}

0 comments on commit c67a2bd

Please sign in to comment.