diff --git a/src/lists.rs b/src/lists.rs index 62ad48971d5..b5a8ba5ae8d 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -303,7 +303,9 @@ pub fn write_list(items: I, formatting: &ListFormatting) -> Option Shape::legacy(width, offset), formatting.config)); - result.push(' '); + if !formatted_comment.starts_with('\n') { + result.push(' '); + } result.push_str(&formatted_comment); } diff --git a/tests/source/space-not-before-newline.rs b/tests/source/space-not-before-newline.rs new file mode 100644 index 00000000000..2a1e1856908 --- /dev/null +++ b/tests/source/space-not-before-newline.rs @@ -0,0 +1,8 @@ +struct Foo { + a: (), + // spaces ^^^ to be removed +} +enum Foo { + Bar, + // spaces ^^^ to be removed +} diff --git a/tests/target/space-not-before-newline.rs b/tests/target/space-not-before-newline.rs new file mode 100644 index 00000000000..9d75b726aa0 --- /dev/null +++ b/tests/target/space-not-before-newline.rs @@ -0,0 +1,8 @@ +struct Foo { + a: (), + // spaces ^^^ to be removed +} +enum Foo { + Bar, + // spaces ^^^ to be removed +}