about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <mail@marcusklaas.nl>2016-04-14 20:42:38 +0200
committerMarcus Klaas de Vries <mail@marcusklaas.nl>2016-04-14 20:42:38 +0200
commit320df84e96bcdb92dbb6ed83db4093106fa9ee0b (patch)
tree8b3e68c02ea774d09a139027d3f3d297f739d098
parent3cc24c6a1acec89f977f0edca0dd0a82eeba2588 (diff)
Fix brace indentation for impl items (#927)
-rw-r--r--src/items.rs8
-rw-r--r--tests/source/impls.rs10
-rw-r--r--tests/target/impls.rs12
3 files changed, 27 insertions, 3 deletions
diff --git a/src/items.rs b/src/items.rs
index 7eddf63dd62..cee1fc4f13e 100644
--- a/src/items.rs
+++ b/src/items.rs
@@ -499,7 +499,8 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
         if try_opt!(is_impl_single_line(context, &items, &result, &where_clause_str, &item)) {
             result.push_str(&where_clause_str);
             if where_clause_str.contains('\n') {
-                result.push_str("\n{\n}");
+                let white_space = offset.to_string(context.config);
+                result.push_str(&format!("\n{}{{\n{}}}", &white_space, &white_space));
             } else {
                 result.push_str(" {}");
             }
@@ -519,9 +520,10 @@ pub fn format_impl(context: &RewriteContext, item: &ast::Item, offset: Indent) -
             BraceStyle::PreferSameLine => result.push(' '),
             BraceStyle::SameLineWhere => {
                 if !where_clause_str.is_empty() {
-                    result.push('\n')
+                    result.push('\n');
+                    result.push_str(&offset.to_string(context.config));
                 } else {
-                    result.push(' ')
+                    result.push(' ');
                 }
             }
         }
diff --git a/tests/source/impls.rs b/tests/source/impls.rs
index e96baa91473..0eb084018bc 100644
--- a/tests/source/impls.rs
+++ b/tests/source/impls.rs
@@ -87,3 +87,13 @@ pub impl<T> Foo for Bar<T> where T: Foo
 }
 
 pub impl<T, Z> Foo for Bar<T, Z> where T: Foo, Z: Baz {}
+
+mod m {
+    impl<T> PartialEq for S<T> where T: PartialEq {
+        fn eq(&self, other: &Self) {
+            true
+        }
+      }
+
+        impl<T> PartialEq for S<T> where T: PartialEq {      }
+ }
diff --git a/tests/target/impls.rs b/tests/target/impls.rs
index c592ab6f9f9..38c972c0031 100644
--- a/tests/target/impls.rs
+++ b/tests/target/impls.rs
@@ -112,3 +112,15 @@ pub impl<T, Z> Foo for Bar<T, Z>
           Z: Baz
 {
 }
+
+mod m {
+    impl<T> PartialEq for S<T>
+        where T: PartialEq
+    {
+        fn eq(&self, other: &Self) {
+            true
+        }
+    }
+
+    impl<T> PartialEq for S<T> where T: PartialEq {}
+}