diff --git a/rustfmt-core/src/comment.rs b/rustfmt-core/src/comment.rs index 512863c88be..67678f59074 100644 --- a/rustfmt-core/src/comment.rs +++ b/rustfmt-core/src/comment.rs @@ -466,7 +466,7 @@ fn rewrite_comment_inner( } result.push_str(closer); - if result == opener && result.ends_with(' ') { + if result.ends_with(opener) && opener.ends_with(' ') { // Trailing space. result.pop(); } diff --git a/rustfmt-core/tests/target/issue-2346.rs b/rustfmt-core/tests/target/issue-2346.rs new file mode 100644 index 00000000000..07817221a51 --- /dev/null +++ b/rustfmt-core/tests/target/issue-2346.rs @@ -0,0 +1,4 @@ +// rustfmt-normalize_comments: true +// the following empty comment should not have any trailing space added. +// +fn main() {}