Skip to content

Commit 2d5bc69

Browse files
committed
remove trailing whitespaces in missing spans
1 parent 5f3dfe6 commit 2d5bc69

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/missed_spans.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,12 @@ impl<'a> FmtVisitor<'a> {
252252
// - if there isn't one already
253253
// - otherwise, only if the last line is a line comment
254254
if status.line_start <= snippet.len() {
255-
match snippet[status.line_start..].chars().next() {
255+
match snippet[status.line_start..]
256+
.chars()
257+
// skip trailing whitespaces
258+
.skip_while(|c| *c == ' ' || *c == '\t')
259+
.next()
260+
{
256261
Some('\n') | Some('\r') => {
257262
if !subslice.trim_end().ends_with("*/") {
258263
self.push_str("\n");

tests/source/issue-3423.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* a nice comment with a trailing whitespace */
2+
fn foo() {}
3+
4+
/* a nice comment with a trailing tab */
5+
fn bar() {}

tests/target/issue-3423.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* a nice comment with a trailing whitespace */
2+
fn foo() {}
3+
4+
/* a nice comment with a trailing tab */
5+
fn bar() {}

0 commit comments

Comments
 (0)