Skip to content

Commit a275a05

Browse files
authored
Merge pull request #2920 from topecongiro/issue-2919
Use correct max width when formatting macro body
2 parents 7c1ad96 + b318e5a commit a275a05

File tree

3 files changed

+55
-9
lines changed

3 files changed

+55
-9
lines changed

src/macros.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,20 +1277,22 @@ impl MacroBranch {
12771277
let body_indent = if has_block_body {
12781278
shape.indent
12791279
} else {
1280-
// We'll hack the indent below, take this into account when formatting,
1281-
let body_indent = shape.indent.block_indent(&config);
1282-
let new_width = config.max_width() - body_indent.width();
1283-
config.set().max_width(new_width);
1284-
body_indent
1280+
shape.indent.block_indent(&config)
12851281
};
1282+
let new_width = config.max_width() - body_indent.width();
1283+
config.set().max_width(new_width);
12861284

12871285
// First try to format as items, then as statements.
12881286
let new_body = match ::format_snippet(&body_str, &config) {
12891287
Some(new_body) => new_body,
1290-
None => match ::format_code_block(&body_str, &config) {
1291-
Some(new_body) => new_body,
1292-
None => return None,
1293-
},
1288+
None => {
1289+
let new_width = new_width + config.tab_spaces();
1290+
config.set().max_width(new_width);
1291+
match ::format_code_block(&body_str, &config) {
1292+
Some(new_body) => new_body,
1293+
None => return None,
1294+
}
1295+
}
12941296
};
12951297
let new_body = wrap_str(new_body, config.max_width(), shape)?;
12961298

tests/source/macro_rules.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,19 @@ macro_rules! impl_as_byte_slice_arrays {
263263
}
264264
};
265265
}
266+
267+
// #2919
268+
fn foo() {
269+
{
270+
macro_rules! touch_value {
271+
($func:ident, $value:expr) => {{
272+
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendMode::paTouch);
273+
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppend);
274+
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
275+
let result = APIIIIIIIII::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
276+
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendMMMMMMMMMM);
277+
debug_assert!(result == 0);
278+
}};
279+
}
280+
}
281+
}

tests/target/macro_rules.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,31 @@ macro_rules! impl_as_byte_slice_arrays {
305305
}
306306
};
307307
}
308+
309+
// #2919
310+
fn foo() {
311+
{
312+
macro_rules! touch_value {
313+
($func:ident, $value:expr) => {{
314+
let result = API::get_cached().$func(
315+
self,
316+
key.as_ptr(),
317+
$value,
318+
ffi::VSPropAppendMode::paTouch,
319+
);
320+
let result = API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppend);
321+
let result =
322+
API::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
323+
let result =
324+
APIIIIIIIII::get_cached().$func(self, key.as_ptr(), $value, ffi::VSPropAppendM);
325+
let result = API::get_cached().$func(
326+
self,
327+
key.as_ptr(),
328+
$value,
329+
ffi::VSPropAppendMMMMMMMMMM,
330+
);
331+
debug_assert!(result == 0);
332+
}};
333+
}
334+
}
335+
}

0 commit comments

Comments
 (0)