about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSinh Pham <phamansinh@gmail.com>2015-09-07 00:24:24 -0400
committerSinh Pham <phamansinh@gmail.com>2015-09-07 00:30:46 -0400
commit94a26f3c9cdb335ec0ae67d4dd56d656309acefb (patch)
treef200a28443957399f9b4058ca6ef08f491e58b8a
parent2a61a989d5074069cf63abd4364470c1d0780da6 (diff)
Fix https://github.com/nrc/rustfmt/issues/278
-rw-r--r--src/comment.rs6
-rw-r--r--tests/source/struct_lits.rs15
-rw-r--r--tests/target/struct_lits.rs15
3 files changed, 35 insertions, 1 deletions
diff --git a/src/comment.rs b/src/comment.rs
index 0db2aefe013..f1cecd7318b 100644
--- a/src/comment.rs
+++ b/src/comment.rs
@@ -70,7 +70,11 @@ pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usiz
             if line.len() > max_chars {
                 acc.push_str(&rewrite_string(line, &fmt));
             } else {
-                acc.push_str(line);
+                if line.len() == 0 {
+                    acc.pop(); // Remove space if this is an empty comment.
+                } else {
+                    acc.push_str(line);
+                }
             }
 
             (false, acc)
diff --git a/tests/source/struct_lits.rs b/tests/source/struct_lits.rs
index 8894508fd98..ead7b749d5a 100644
--- a/tests/source/struct_lits.rs
+++ b/tests/source/struct_lits.rs
@@ -68,3 +68,18 @@ fn issue201() {
 fn issue201_2() {
     let s = S{a: S2{    .. c}, ..  b};
 }
+
+fn issue278() {
+    let s = S {
+        a: 0,
+        //       
+        b: 0,
+    };
+    let s1 = S {
+        a: 0,
+        // foo
+        //      
+        // bar
+        b: 0,
+    };
+}
diff --git a/tests/target/struct_lits.rs b/tests/target/struct_lits.rs
index 81c60381ed8..b95772d41ec 100644
--- a/tests/target/struct_lits.rs
+++ b/tests/target/struct_lits.rs
@@ -86,3 +86,18 @@ fn issue201() {
 fn issue201_2() {
     let s = S { a: S2 { ..c }, ..b };
 }
+
+fn issue278() {
+    let s = S {
+        a: 0,
+        //
+        b: 0,
+    };
+    let s1 = S {
+        a: 0,
+        // foo
+        //
+        // bar
+        b: 0,
+    };
+}