Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 16d5f50

Browse files
authored
Merge pull request rust-lang#3172 from scampi/issue3153
trim the start of a line when wrapping an item in preparation for formatting
2 parents bd29e16 + 5a2ebdd commit 16d5f50

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/comment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ impl CodeBlockAttribute {
398398
/// Block that is formatted as an item.
399399
///
400400
/// An item starts with either a star `*` or a dash `-`. Different level of indentation are
401-
/// handled.
401+
/// handled by shrinking the shape accordingly.
402402
struct ItemizedBlock {
403403
/// the number of whitespaces up to the item sigil
404404
indent: usize,
@@ -585,7 +585,7 @@ impl<'a> CommentRewrite<'a> {
585585

586586
if let Some(ref ib) = self.item_block {
587587
if ib.in_block(&line) {
588-
self.item_block_buffer.push_str(&line);
588+
self.item_block_buffer.push_str(line.trim_start());
589589
self.item_block_buffer.push('\n');
590590
return false;
591591
}

tests/source/issue-3153.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-wrap_comments: true
2+
3+
/// This may panic if:
4+
/// - there are fewer than `max_header_bytes` bytes preceding the body
5+
/// - there are fewer than `max_footer_bytes` bytes following the body
6+
/// - the sum of the body bytes and post-body bytes is less than the sum
7+
/// of `min_body_and_padding_bytes` and `max_footer_bytes` (in other
8+
/// words, the minimum body and padding byte requirement is not met)
9+
fn foo() {}

tests/target/issue-3153.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// rustfmt-wrap_comments: true
2+
3+
/// This may panic if:
4+
/// - there are fewer than `max_header_bytes` bytes preceding the body
5+
/// - there are fewer than `max_footer_bytes` bytes following the body
6+
/// - the sum of the body bytes and post-body bytes is less than the sum of
7+
/// `min_body_and_padding_bytes` and `max_footer_bytes` (in other words, the
8+
/// minimum body and padding byte requirement is not met)
9+
fn foo() {}

0 commit comments

Comments
 (0)