diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 008efd2bef1..27b94a6c8ae 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -252,7 +252,12 @@ impl<'a> FmtVisitor<'a> { // - if there isn't one already // - otherwise, only if the last line is a line comment if status.line_start <= snippet.len() { - match snippet[status.line_start..].chars().next() { + match snippet[status.line_start..] + .chars() + // skip trailing whitespaces + .skip_while(|c| *c == ' ' || *c == '\t') + .next() + { Some('\n') | Some('\r') => { if !subslice.trim_end().ends_with("*/") { self.push_str("\n"); diff --git a/tests/source/issue-3423.rs b/tests/source/issue-3423.rs new file mode 100644 index 00000000000..fbe8e5c372e --- /dev/null +++ b/tests/source/issue-3423.rs @@ -0,0 +1,5 @@ +/* a nice comment with a trailing whitespace */ +fn foo() {} + +/* a nice comment with a trailing tab */ +fn bar() {} diff --git a/tests/target/issue-3423.rs b/tests/target/issue-3423.rs new file mode 100644 index 00000000000..cd60251771d --- /dev/null +++ b/tests/target/issue-3423.rs @@ -0,0 +1,5 @@ +/* a nice comment with a trailing whitespace */ +fn foo() {} + +/* a nice comment with a trailing tab */ +fn bar() {}