From 2727d41ddb676787729cd5632ecedcc4a2d299bb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Luis=20Leal=20Cardoso=20Junior?=
 <andrehjr@gmail.com>
Date: Tue, 25 Sep 2018 08:53:42 -0300
Subject: [PATCH] Makes brace behavior consistent with empty bodies for traits
 and impls

Adds a newline before the last brace on impls without a body if the first brace is also on a newline
---
 src/items.rs                   |  5 ++---
 tests/target/big-impl-block.rs |  3 ++-
 tests/target/impls.rs          | 12 ++++++++----
 3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/items.rs b/src/items.rs
index 46abe086717..a7ba48776d6 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -755,11 +755,10 @@ pub fn format_impl(
             result.push_str(&inner_indent_str);
             result.push_str(visitor.buffer.to_string().trim());
             result.push_str(&outer_indent_str);
-        }
-
-        if result.ends_with('{') && !context.config.empty_item_single_line() {
+        } else if need_newline || !context.config.empty_item_single_line() {
             result.push_str(&sep);
         }
+
         result.push('}');
 
         Some(result)
diff --git a/tests/target/big-impl-block.rs b/tests/target/big-impl-block.rs
index fbf1757c635..e3728caba3f 100644
--- a/tests/target/big-impl-block.rs
+++ b/tests/target/big-impl-block.rs
@@ -78,4 +78,5 @@ where
     S: event::Stream,
     F: for<'t> FnMut(transform::Api<'t, Stream<ContentStream<S>>>) -> transform::Api<'t, X>,
     X: event::Stream,
-{}
+{
+}
diff --git a/tests/target/impls.rs b/tests/target/impls.rs
index 390f1a12cd3..0777a7ed249 100644
--- a/tests/target/impls.rs
+++ b/tests/target/impls.rs
@@ -134,11 +134,13 @@ mod m {
 
 impl<BorrowType, K, V, NodeType, HandleType>
     Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType>
-{}
+{
+}
 
 impl<BorrowType, K, V, NodeType, HandleType> PartialEq
     for Handle<NodeRef<BorrowType, K, V, NodeType>, HandleType>
-{}
+{
+}
 
 mod x {
     impl<A, B, C, D> Foo
@@ -147,7 +149,8 @@ mod x {
         B: 'static,
         C: 'static,
         D: 'static,
-    {}
+    {
+    }
 }
 
 impl<ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNodeFoo>
@@ -229,4 +232,5 @@ impl<'seq1, 'seq2, 'body, 'scope, Channel>
     >
 where
     Channel: DmaChannel,
-{}
+{
+}