mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 04:04:06 +00:00
Align post comments with items when the it starts with newline
This commit is contained in:
parent
53d7489221
commit
d92cfff43b
16
src/lists.rs
16
src/lists.rs
@ -410,7 +410,9 @@ where
|
||||
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 @@ where
|
||||
|| 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 @@ where
|
||||
{
|
||||
result.push(' ');
|
||||
}
|
||||
} else {
|
||||
result.push('\n');
|
||||
result.push_str(&indent_str);
|
||||
}
|
||||
if formatted_comment.contains('\n') {
|
||||
item_max_width = None;
|
||||
|
Loading…
Reference in New Issue
Block a user