about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <mail@marcusklaas.nl>2016-01-12 22:52:34 +0100
committerMarcus Klaas de Vries <mail@marcusklaas.nl>2016-01-12 22:52:34 +0100
commitba465e0fc2b2203f7ebbdd50be7400ae43389467 (patch)
tree810121a5400e606c692a9546b88ebfb57d2f7e9f /src
parent4cefecb495c7a425935563a6f15e6b2b9e86e316 (diff)
parent7f8b9bd35682bbe793412342b8d5dfa25cce7869 (diff)
Merge pull request #766 from ConnorGBrewster/fix-#489
Added option for tighter punctuation in types. fixes #489
Diffstat (limited to 'src')
-rw-r--r--src/config.rs9
-rw-r--r--src/types.rs15
2 files changed, 22 insertions, 2 deletions
diff --git a/src/config.rs b/src/config.rs
index 3e251ad1e39..7c8505e5e09 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -73,6 +73,13 @@ configuration_option_enum! { Density:
     CompressedIfEmpty,
 }
 
+configuration_option_enum! { TypeDensity:
+    // No spaces around "=" and "+"
+    Compressed,
+    // Spaces around " = " and " + "
+    Wide,
+}
+
 impl Density {
     pub fn to_list_tactic(self) -> ListTactic {
         match self {
@@ -279,6 +286,8 @@ create_config! {
     fn_args_density: Density, Density::Tall, "Argument density in functions";
     fn_args_layout: StructLitStyle, StructLitStyle::Visual, "Layout of function arguments";
     fn_arg_indent: BlockIndentStyle, BlockIndentStyle::Visual, "Indent on function arguments";
+    type_punctuation_density: TypeDensity, TypeDensity::Wide,
+        "Determines if '+' or '=' are wrapped in spaces in the punctuation of types";
     // Should we at least try to put the where clause on the same line as the rest of the
     // function decl?
     where_density: Density, Density::CompressedIfEmpty, "Density of a where clause";
diff --git a/src/types.rs b/src/types.rs
index 82a335c3012..32ae4689414 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -21,6 +21,7 @@ use lists::{format_item_list, itemize_list, format_fn_args};
 use rewrite::{Rewrite, RewriteContext};
 use utils::{extra_offset, span_after, format_mutability, wrap_str};
 use expr::{rewrite_unary_prefix, rewrite_pair, rewrite_tuple};
+use config::TypeDensity;
 
 // Does not wrap on simple segments.
 pub fn rewrite_path(context: &RewriteContext,
@@ -424,7 +425,12 @@ impl Rewrite for ast::TyParam {
             result.push_str(&bounds);
         }
         if let Some(ref def) = self.default {
-            result.push_str(" = ");
+
+            let eq_str = match context.config.type_punctuation_density {
+                TypeDensity::Compressed => "=",
+                TypeDensity::Wide => " = ",
+            };
+            result.push_str(eq_str);
             let budget = try_opt!(width.checked_sub(result.len()));
             let rewrite = try_opt!(def.rewrite(context, budget, offset + result.len()));
             result.push_str(&rewrite);
@@ -467,8 +473,13 @@ impl Rewrite for ast::Ty {
             ast::TyObjectSum(ref ty, ref bounds) => {
                 let ty_str = try_opt!(ty.rewrite(context, width, offset));
                 let overhead = ty_str.len() + 3;
-                Some(format!("{} + {}",
+                let plus_str = match context.config.type_punctuation_density {
+                    TypeDensity::Compressed => "+",
+                    TypeDensity::Wide => " + ",
+                };
+                Some(format!("{}{}{}",
                              ty_str,
+                             plus_str,
                              try_opt!(bounds.rewrite(context,
                                                      try_opt!(width.checked_sub(overhead)),
                                                      offset + overhead))))