From 2d5bc69475e727165d220d021bb589de00623d16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Campinas?= Date: Sat, 16 Mar 2019 12:23:02 +0100 Subject: [PATCH] remove trailing whitespaces in missing spans --- src/missed_spans.rs | 7 ++++++- tests/source/issue-3423.rs | 5 +++++ tests/target/issue-3423.rs | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/source/issue-3423.rs create mode 100644 tests/target/issue-3423.rs 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() {}