diff --git a/src/comment.rs b/src/comment.rs index b7d7a396a67..709031dda44 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -885,6 +885,9 @@ impl<'a> CommentRewrite<'a> { // Remove space if this is an empty comment or a doc comment. self.result.pop(); } + if self.code_block_attr.is_some() && self.is_prev_line_multi_line { + self.result.push_str(&self.comment_line_separator); + } self.result.push_str(line); self.fmt.shape = Shape::legacy(self.max_width, self.fmt_indent); self.is_prev_line_multi_line = false; diff --git a/tests/target/issue-6416/unwrapped.rs b/tests/target/issue-6416/unwrapped.rs new file mode 100644 index 00000000000..5214dde8185 --- /dev/null +++ b/tests/target/issue-6416/unwrapped.rs @@ -0,0 +1,7 @@ +// rustfmt-wrap_comments: false + +/// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam +/// ``` +/// let foo = 0; +/// ``` +fn bar() {} diff --git a/tests/target/issue-6416/wrapped.rs b/tests/target/issue-6416/wrapped.rs new file mode 100644 index 00000000000..b7be6b4f71c --- /dev/null +++ b/tests/target/issue-6416/wrapped.rs @@ -0,0 +1,8 @@ +// rustfmt-wrap_comments: true + +/// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam +/// lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam +/// ``` +/// let foo = 0; +/// ``` +fn bar() {}