diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 384de1ce9ae..b2db474b06b 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -270,15 +270,15 @@ impl<'a> FmtVisitor<'a> { if on_same_line { match subslice.find('\n') { None => { - self.push_str(subslice); + self.push_str(subslice.trim_end()); } Some(offset) if offset + 1 == subslice.len() => { - self.push_str(&subslice[..offset]); + self.push_str(&subslice[..offset].trim_end()); } Some(offset) => { // keep first line as is: if it were too long and wrapped, it may get mixed // with the other lines. - let first_line = &subslice[..offset]; + let first_line = &subslice[..offset].trim_end(); self.push_str(first_line); self.push_str(&comment_indent.to_string_with_newline(self.config)); diff --git a/tests/source/issue_6568.rs b/tests/source/issue_6568.rs new file mode 100644 index 00000000000..8c76a8cfb79 --- /dev/null +++ b/tests/source/issue_6568.rs @@ -0,0 +1,3 @@ +// rustfmt-style_edition: 2024 + +fn f() {} // This has trailing whitespace diff --git a/tests/target/issue_6568.rs b/tests/target/issue_6568.rs new file mode 100644 index 00000000000..da59ea87196 --- /dev/null +++ b/tests/target/issue_6568.rs @@ -0,0 +1,3 @@ +// rustfmt-style_edition: 2024 + +fn f() {} // This has trailing whitespace