]> git.lizzy.rs Git - rust.git/commitdiff
Preserve two or more trailing spaces in doc comment
authortopecongiro <seuchida@gmail.com>
Thu, 15 Feb 2018 07:41:47 +0000 (16:41 +0900)
committertopecongiro <seuchida@gmail.com>
Thu, 15 Feb 2018 07:41:47 +0000 (16:41 +0900)
rustdoc treats two or more trailing spaces as a line break.

rustfmt-core/src/comment.rs
rustfmt-core/tests/source/markdown-comment.rs
rustfmt-core/tests/target/markdown-comment.rs

index 523282396d04c59be6a2dde9fb7f163eaadb5ebe..dc0c59a617e9dd8be0792b173c9720f9655370ca 100644 (file)
@@ -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();
index c3633141ba5d59b32feec43b2b62cb2935ef36e4..1ec26562fe2824af64c7c6e24c2c191220ffcf5a 100644 (file)
@@ -4,7 +4,7 @@
 //! hello world  
 //! hello world 
 
-/// hello world  
+/// hello world    
 /// hello world 
 /// hello world  
 fn foo() {
index 5c4c413bddf5959b51b3b22091cf3dde6c6c1738..71a9921d2862897ac2180eadad27706e141ec706 100644 (file)
@@ -4,7 +4,7 @@
 //! hello world  
 //! hello world
 
-/// hello world  
+/// hello world    
 /// hello world
 /// hello world  
 fn foo() {