From: topecongiro Date: Thu, 23 Nov 2017 03:38:34 +0000 (+0900) Subject: Align post comments with items when the it starts with newline X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=d92cfff43b2dc1ce43fdac172855a8d34bb79c8c;p=rust.git Align post comments with items when the it starts with newline --- diff --git a/src/lists.rs b/src/lists.rs index 1e073945c0b..bf0d276574e 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -410,7 +410,9 @@ pub fn write_list(items: I, formatting: &ListFormatting) -> Option formatting.config.max_width(), )); } - let overhead = if let Some(max_width) = *item_max_width { + let overhead = if starts_with_newline(comment) { + 0 + } else if let Some(max_width) = *item_max_width { max_width + 2 } else { // 1 = space between item and comment. @@ -425,12 +427,17 @@ pub fn write_list(items: I, formatting: &ListFormatting) -> Option || comment.trim().contains('\n') || comment.trim().len() > width; - rewrite_comment(comment, block_style, comment_shape, formatting.config) + rewrite_comment( + comment.trim_left(), + block_style, + comment_shape, + formatting.config, + ) }; let mut formatted_comment = rewrite_post_comment(&mut item_max_width)?; - if !starts_with_newline(&formatted_comment) { + if !starts_with_newline(&comment) { let mut comment_alignment = post_comment_alignment(item_max_width, inner_item.len()); if first_line_width(&formatted_comment) + last_line_width(&result) @@ -448,6 +455,9 @@ pub fn write_list(items: I, formatting: &ListFormatting) -> Option { result.push(' '); } + } else { + result.push('\n'); + result.push_str(&indent_str); } if formatted_comment.contains('\n') { item_max_width = None;