Skip to content

Commit ee92a17

Browse files
committed
fix: remove trailing spaces when rewriting same line missing comments
Fixes 6568 When using `style_edition=2024` trailing whitespace was not properly removed when foramtting same line comments.
1 parent 1443bba commit ee92a17

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/missed_spans.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,15 @@ impl<'a> FmtVisitor<'a> {
270270
if on_same_line {
271271
match subslice.find('\n') {
272272
None => {
273-
self.push_str(subslice);
273+
self.push_str(subslice.trim_end());
274274
}
275275
Some(offset) if offset + 1 == subslice.len() => {
276-
self.push_str(&subslice[..offset]);
276+
self.push_str(&subslice[..offset].trim_end());
277277
}
278278
Some(offset) => {
279279
// keep first line as is: if it were too long and wrapped, it may get mixed
280280
// with the other lines.
281-
let first_line = &subslice[..offset];
281+
let first_line = &subslice[..offset].trim_end();
282282
self.push_str(first_line);
283283
self.push_str(&comment_indent.to_string_with_newline(self.config));
284284

tests/source/issue_6568.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// rustfmt-style_edition: 2024
2+
3+
fn f() {} // This has trailing whitespace

tests/target/issue_6568.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// rustfmt-style_edition: 2024
2+
3+
fn f() {} // This has trailing whitespace

0 commit comments

Comments
 (0)