about summary refs log tree commit diff
path: root/src/types.rs
diff options
context:
space:
mode:
authorMikko Rantanen <jubjub@jubjubnest.net>2016-10-13 04:34:08 +0300
committerNick Cameron <nrc@ncameron.org>2016-10-13 14:34:08 +1300
commit7be202fa3c53ab1d4e208245653fde033ec0131c (patch)
tree00683c92e043cee446aab7b103ac42bde18ecf17 /src/types.rs
parent724f75eaa5d5eb72baabab7bc3ec3b8ed0d52815 (diff)
Add support for spaces_within_parens config (#1187)
* Add support for spaces_within_parens config

* Changes based on review comments
Diffstat (limited to 'src/types.rs')
-rw-r--r--src/types.rs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/types.rs b/src/types.rs
index a718750db95..624f17f6be8 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -311,7 +311,11 @@ fn format_function_type<'a, I>(inputs: I,
         String::new()
     };
 
-    Some(format!("({}){}{}", list_str, infix, output))
+    Some(if context.config.spaces_within_parens {
+        format!("( {} ){}{}", list_str, infix, output)
+    } else {
+        format!("({}){}{}", list_str, infix, output)
+    })
 }
 
 impl Rewrite for ast::WherePredicate {
@@ -575,7 +579,12 @@ impl Rewrite for ast::Ty {
             // comments.
             ast::TyKind::Paren(ref ty) => {
                 let budget = try_opt!(width.checked_sub(2));
-                ty.rewrite(context, budget, offset + 1).map(|ty_str| format!("({})", ty_str))
+                ty.rewrite(context, budget, offset + 1)
+                    .map(|ty_str| if context.config.spaces_within_parens {
+                        format!("( {} )", ty_str)
+                    } else {
+                        format!("({})", ty_str)
+                    })
             }
             ast::TyKind::Vec(ref ty) => {
                 let budget = try_opt!(width.checked_sub(2));