From 6f38a4aeab697dd6d52ca4cdcdec6d7d03c960f2 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Thu, 15 Feb 2018 16:41:47 +0900 Subject: [PATCH] Preserve two or more trailing spaces in doc comment rustdoc treats two or more trailing spaces as a line break. --- rustfmt-core/src/comment.rs | 8 +++----- rustfmt-core/tests/source/markdown-comment.rs | 2 +- rustfmt-core/tests/target/markdown-comment.rs | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/rustfmt-core/src/comment.rs b/rustfmt-core/src/comment.rs index 523282396d04..dc0c59a617e9 100644 --- a/rustfmt-core/src/comment.rs +++ b/rustfmt-core/src/comment.rs @@ -508,11 +508,9 @@ pub fn recover_missing_comment_in_span( } } -/// Trim trailing whitespaces unless they consist of two whitespaces. +/// Trim trailing whitespaces unless they consist of two or more whitespaces. fn trim_right_unless_two_whitespaces(s: &str, is_doc_comment: bool) -> &str { - if is_doc_comment && s.ends_with(" ") - && !s.chars().rev().nth(2).map_or(true, char::is_whitespace) - { + if is_doc_comment && s.ends_with(" ") { s } else { s.trim_right() @@ -541,7 +539,7 @@ fn light_rewrite_comment( } else { "" }; - // Preserve markdown's double-space line break syntax. + // Preserve markdown's double-space line break syntax in doc comment. trim_right_unless_two_whitespaces(left_trimmed, is_doc_comment) }) .collect(); diff --git a/rustfmt-core/tests/source/markdown-comment.rs b/rustfmt-core/tests/source/markdown-comment.rs index c3633141ba5d..1ec26562fe28 100644 --- a/rustfmt-core/tests/source/markdown-comment.rs +++ b/rustfmt-core/tests/source/markdown-comment.rs @@ -4,7 +4,7 @@ //! hello world //! hello world -/// hello world +/// hello world /// hello world /// hello world fn foo() { diff --git a/rustfmt-core/tests/target/markdown-comment.rs b/rustfmt-core/tests/target/markdown-comment.rs index 5c4c413bddf5..71a9921d2862 100644 --- a/rustfmt-core/tests/target/markdown-comment.rs +++ b/rustfmt-core/tests/target/markdown-comment.rs @@ -4,7 +4,7 @@ //! hello world //! hello world -/// hello world +/// hello world /// hello world /// hello world fn foo() {