Skip to content

Commit 2a55cf2

Browse files
committed
Changes per reviewer comments
1 parent 128133e commit 2a55cf2

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

src/macros.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,10 +1220,13 @@ impl MacroBranch {
12201220

12211221
// 5 = " => {"
12221222
let old_body = context.snippet(self.body).trim();
1223-
let prefix_width = 5 + if context.config.format_macro_bodies() {
1224-
old_body.find(|ch| ch != '{').unwrap_or(old_body.len()) // " => {{..."
1223+
let has_block_body = old_body.starts_with('{');
1224+
let prefix_width = if has_block_body && context.config.format_macro_bodies() {
1225+
// 6 = " => {{"
1226+
6
12251227
} else {
1226-
0
1228+
// 5 = " => {"
1229+
5
12271230
};
12281231
let mut result =
12291232
format_macro_args(context, self.args.clone(), shape.sub_width(prefix_width)?)?;
@@ -1245,7 +1248,6 @@ impl MacroBranch {
12451248
// variables for new names with the same length first.
12461249

12471250
let (body_str, substs) = replace_names(old_body)?;
1248-
let has_block_body = old_body.starts_with('{');
12491251

12501252
let mut config = context.config.clone();
12511253
config.set().hide_parse_errors(true);

tests/source/issue-3805.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ return;
77
}};
88
}
99

10+
// Spaces between the `{` and `}`
11+
macro_rules! test {
12+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => { {
13+
return;
14+
} };
15+
}
16+
17+
// Multi `{}`
18+
macro_rules! test {
19+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => {{{{
20+
return;
21+
}}}};
22+
}
23+
24+
// Multi `{}` with spaces
25+
macro_rules! test {
26+
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr) => { { { {
27+
return;
28+
} } } };
29+
}
30+
1031
// Line length 102
1132
macro_rules! test {
1233
($aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeiou:expr, $add:expr) => {{

tests/target/issue-3805.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,41 @@ macro_rules! test {
99
}};
1010
}
1111

12+
// Spaces between the `{` and `}`
13+
macro_rules! test {
14+
(
15+
$aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr
16+
) => {{
17+
return;
18+
}};
19+
}
20+
21+
// Multi `{}`
22+
macro_rules! test {
23+
(
24+
$aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr
25+
) => {{
26+
{
27+
{
28+
return;
29+
}
30+
}
31+
}};
32+
}
33+
34+
// Multi `{}` with spaces
35+
macro_rules! test {
36+
(
37+
$aasdfghj:expr, $qwertyuiop:expr, $zxcvbnmasdfghjkl:expr, $aeiouaeiouaeio:expr, $add:expr
38+
) => {{
39+
{
40+
{
41+
return;
42+
}
43+
}
44+
}};
45+
}
46+
1247
// Line length 102
1348
macro_rules! test {
1449
(

0 commit comments

Comments
 (0)