Skip to content

Commit 6f7aeed

Browse files
grant0417ytmimi
authored andcommitted
fix: wrap_comments creating invalid code blocks
1 parent e6bc629 commit 6f7aeed

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/comment.rs

+3
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,9 @@ impl<'a> CommentRewrite<'a> {
885885
// Remove space if this is an empty comment or a doc comment.
886886
self.result.pop();
887887
}
888+
if self.code_block_attr.is_some() && self.is_prev_line_multi_line {
889+
self.result.push_str(&self.comment_line_separator);
890+
}
888891
self.result.push_str(line);
889892
self.fmt.shape = Shape::legacy(self.max_width, self.fmt_indent);
890893
self.is_prev_line_multi_line = false;

tests/target/issue-5244/unwrapped.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rustfmt-wrap_comments: false
2+
3+
/// Here is me writing some documentation that is too long oh me oh my now some code please!
4+
/// ```
5+
/// test
6+
/// ```
7+
fn foo() {}

tests/target/issue-5244/wrapped.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// rustfmt-wrap_comments: true
2+
3+
/// Here is me writing some documentation that is too long oh me oh my now some
4+
/// code please!
5+
/// ```
6+
/// test
7+
/// ```
8+
fn foo() {}

0 commit comments

Comments
 (0)