]> git.lizzy.rs Git - rust.git/commitdiff
Fix brace indentation for impl items (#927)
authorMarcus Klaas de Vries <mail@marcusklaas.nl>
Thu, 14 Apr 2016 18:42:38 +0000 (20:42 +0200)
committerMarcus Klaas de Vries <mail@marcusklaas.nl>
Thu, 14 Apr 2016 18:42:38 +0000 (20:42 +0200)
src/items.rs
tests/source/impls.rs
tests/target/impls.rs

index 7eddf63dd62a3d73869a2b8257b1c28df2fb1837..cee1fc4f13e09f5b7186dc4bf8c175df1609a671 100644 (file)
@@ -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(' ');
                 }
             }
         }
index e96baa91473ca1e890dbbfb274b1d9f2d7d0ea37..0eb084018bc9ec991e5950d4ece4a4cda23cf293 100644 (file)
@@ -87,3 +87,13 @@ fn foo() { "hi" }
 }
 
 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 {      }
+ }
index c592ab6f9f92aeca62ab687ba2101c951a0154c5..38c972c003181f80dbb43c89ca4593be43882b54 100644 (file)
@@ -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 {}
+}