]> git.lizzy.rs Git - rust.git/commitdiff
Put empty modules on one line
authorNick Cameron <ncameron@mozilla.com>
Thu, 28 Jan 2016 06:53:41 +0000 (19:53 +1300)
committerNick Cameron <ncameron@mozilla.com>
Thu, 28 Jan 2016 06:53:41 +0000 (19:53 +1300)
Fixes #463

src/visitor.rs
tests/target/comment2.rs
tests/target/comment3.rs
tests/target/mod-1.rs

index 569bacc1300e6f747540ff0606b0cd990e321d3b..073a05ef2bc74eb3c8b8835684a653dfab06d365 100644 (file)
@@ -454,11 +454,19 @@ fn format_mod(&mut self, m: &ast::Mod, vis: ast::Visibility, s: Span, ident: ast
 
         if is_internal {
             self.buffer.push_str(" {");
-            self.last_pos = ::utils::span_after(s, "{", self.codemap);
-            self.block_indent = self.block_indent.block_indent(self.config);
-            self.walk_mod_items(m);
-            self.format_missing_with_indent(m.inner.hi - BytePos(1));
-            self.close_block();
+            // Hackery to account for the closing }.
+            let mod_lo = ::utils::span_after(s, "{", self.codemap);
+            let body_snippet = self.snippet(codemap::mk_sp(mod_lo, m.inner.hi - BytePos(1)));
+            let body_snippet = body_snippet.trim();
+            if body_snippet.is_empty() {
+                self.buffer.push_str("}");
+            } else {
+                self.last_pos = mod_lo;
+                self.block_indent = self.block_indent.block_indent(self.config);
+                self.walk_mod_items(m);
+                self.format_missing_with_indent(m.inner.hi - BytePos(1));
+                self.close_block();
+            }
             self.last_pos = m.inner.hi;
         } else {
             self.buffer.push_str(";");
index cecb7b0d95f03b89807cf7aa03bef3c6490ecced..04f84a15c957b53bac90f5f3461b98885272edc9 100644 (file)
@@ -2,5 +2,4 @@
 
 /// This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly
 /// and justly.
-pub mod foo {
-}
+pub mod foo {}
index 24598931ed1ffc3dd5d793b1fc65e133192a98be..3a810590d7b3c820719ad3db9a89e15264115498 100644 (file)
@@ -3,5 +3,4 @@
 //! This is a long line that angers rustfmt. Rustfmt shall deal with it swiftly
 //! and justly.
 
-pub mod foo {
-}
+pub mod foo {}
index 6fe2e65c565d2319b9671ba93ec1cab2aefb4de7..abf25b5e649063e6b3a21855cd4deb885a5e06c6 100644 (file)
@@ -2,8 +2,7 @@
 
 mod foo {
     mod bar {
-        mod baz {
-        }
+        mod baz {}
     }
 }
 
@@ -16,9 +15,7 @@ fn foo() {
         }
     }
 
-    mod qux {
-
-    }
+    mod qux {}
 }
 
 mod boxed {