diff --git a/src/comment.rs b/src/comment.rs index eaed5e1d41eb..db5102a3755e 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -398,7 +398,7 @@ impl CodeBlockAttribute { /// Block that is formatted as an item. /// /// An item starts with either a star `*` or a dash `-`. Different level of indentation are -/// handled. +/// handled by shrinking the shape accordingly. struct ItemizedBlock { /// the number of whitespaces up to the item sigil indent: usize, @@ -585,7 +585,7 @@ impl<'a> CommentRewrite<'a> { if let Some(ref ib) = self.item_block { if ib.in_block(&line) { - self.item_block_buffer.push_str(&line); + self.item_block_buffer.push_str(line.trim_start()); self.item_block_buffer.push('\n'); return false; } diff --git a/tests/source/issue-3153.rs b/tests/source/issue-3153.rs new file mode 100644 index 000000000000..2836ce97cf8d --- /dev/null +++ b/tests/source/issue-3153.rs @@ -0,0 +1,9 @@ +// rustfmt-wrap_comments: true + +/// This may panic if: +/// - there are fewer than `max_header_bytes` bytes preceding the body +/// - there are fewer than `max_footer_bytes` bytes following the body +/// - the sum of the body bytes and post-body bytes is less than the sum +/// of `min_body_and_padding_bytes` and `max_footer_bytes` (in other +/// words, the minimum body and padding byte requirement is not met) +fn foo() {} diff --git a/tests/target/issue-3153.rs b/tests/target/issue-3153.rs new file mode 100644 index 000000000000..39e569c0d543 --- /dev/null +++ b/tests/target/issue-3153.rs @@ -0,0 +1,9 @@ +// rustfmt-wrap_comments: true + +/// This may panic if: +/// - there are fewer than `max_header_bytes` bytes preceding the body +/// - there are fewer than `max_footer_bytes` bytes following the body +/// - the sum of the body bytes and post-body bytes is less than the sum of +/// `min_body_and_padding_bytes` and `max_footer_bytes` (in other words, the +/// minimum body and padding byte requirement is not met) +fn foo() {}