Skip to content

Commit 5f4811e

Browse files
ytmimicalebcartwright
authored andcommitted
Handle DefinitiveListTactic::SpecialMacro when writing pre-comments
Resolves 4615 Previously only Vertical and Mixed enum variants of DefinitiveListTactic were considered when rewriting pre-comments for inner items in lists::write_list. Because we failed to considering the SpecialMacro variant we ended up in a scenario where a ListItem with a pre_comment and a pre_comment_style of ListItemCommentStyle::DifferentLine was written on the same line as the list item itself. Now we apply the same pre-comment formatting to SpecialMacro, Vertical, and Mixed variants of DefinitiveListTactic.
1 parent 0cff306 commit 5f4811e

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

src/lists.rs

+24-22
Original file line numberDiff line numberDiff line change
@@ -367,29 +367,31 @@ where
367367
result.push_str(&comment);
368368

369369
if !inner_item.is_empty() {
370-
if tactic == DefinitiveListTactic::Vertical || tactic == DefinitiveListTactic::Mixed
371-
{
372-
// We cannot keep pre-comments on the same line if the comment if normalized.
373-
let keep_comment = if formatting.config.normalize_comments()
374-
|| item.pre_comment_style == ListItemCommentStyle::DifferentLine
375-
{
376-
false
377-
} else {
378-
// We will try to keep the comment on the same line with the item here.
379-
// 1 = ` `
380-
let total_width = total_item_width(item) + item_sep_len + 1;
381-
total_width <= formatting.shape.width
382-
};
383-
if keep_comment {
384-
result.push(' ');
385-
} else {
386-
result.push('\n');
387-
result.push_str(indent_str);
388-
// This is the width of the item (without comments).
389-
line_len = item.item.as_ref().map_or(0, |s| unicode_str_width(&s));
370+
match tactic {
371+
DefinitiveListTactic::SpecialMacro(_)
372+
| DefinitiveListTactic::Vertical
373+
| DefinitiveListTactic::Mixed => {
374+
// We cannot keep pre-comments on the same line if the comment is normalized
375+
let keep_comment = if formatting.config.normalize_comments()
376+
|| item.pre_comment_style == ListItemCommentStyle::DifferentLine
377+
{
378+
false
379+
} else {
380+
// We will try to keep the comment on the same line with the item here.
381+
// 1 = ` `
382+
let total_width = total_item_width(item) + item_sep_len + 1;
383+
total_width <= formatting.shape.width
384+
};
385+
if keep_comment {
386+
result.push(' ');
387+
} else {
388+
result.push('\n');
389+
result.push_str(indent_str);
390+
// This is the width of the item (without comments).
391+
line_len = item.item.as_ref().map_or(0, |s| unicode_str_width(&s));
392+
}
390393
}
391-
} else {
392-
result.push(' ');
394+
_ => result.push(' '),
393395
}
394396
}
395397
item_max_width = None;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
info!(//debug
2+
"{}: sending function_code={:04x} data={:04x} crc=0x{:04X} data={:02X?}",
3+
self.name, function_code, data, crc, output_cmd
4+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
info!(
2+
//debug
3+
"{}: sending function_code={:04x} data={:04x} crc=0x{:04X} data={:02X?}",
4+
self.name, function_code, data, crc, output_cmd
5+
);

0 commit comments

Comments
 (0)