diff --git a/src/comment.rs b/src/comment.rs index 8cd491b6ee38..4a44c77a4a22 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -332,7 +332,11 @@ fn rewrite_comment_inner( inside_code_block = !inside_code_block; } if inside_code_block { - result.push_str(line); + if line.is_empty() && result.ends_with(' ') { + result.pop(); + } else { + result.push_str(line); + } continue; } diff --git a/tests/source/configs-wrap_comments-true.rs b/tests/source/configs-wrap_comments-true.rs index 0f6d021b28ea..39a79a4cacc4 100644 --- a/tests/source/configs-wrap_comments-true.rs +++ b/tests/source/configs-wrap_comments-true.rs @@ -5,3 +5,11 @@ fn main() { // Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. } + +fn code_block() { + // ```rust + // let x = 3; + // + // println!("x = {}", x); + // ``` +} diff --git a/tests/target/configs-wrap_comments-true.rs b/tests/target/configs-wrap_comments-true.rs index 01e861235258..4096fd4d89d2 100644 --- a/tests/target/configs-wrap_comments-true.rs +++ b/tests/target/configs-wrap_comments-true.rs @@ -10,3 +10,11 @@ fn main() { // nostrud exercitation ullamco laboris nisi // ut aliquip ex ea commodo consequat. } + +fn code_block() { + // ```rust + // let x = 3; + // + // println!("x = {}", x); + // ``` +}