]> git.lizzy.rs Git - rust.git/commitdiff
Refactoring exsisting filter_maps to maps
authorJacob Clark <jacob.jh.clark@googlemail.com>
Mon, 6 Jun 2016 23:03:25 +0000 (00:03 +0100)
committerJacob Clark <jacob.jh.clark@googlemail.com>
Mon, 6 Jun 2016 23:03:25 +0000 (00:03 +0100)
src/items.rs
src/types.rs

index fd0dd9d6a67cc6ce558d06ace5fe661384d9f13f..1de56220cf4346740966b1c3820616188346edef 100644 (file)
@@ -1055,9 +1055,10 @@ pub fn rewrite_associated_type(ident: ast::Ident,
 
     let type_bounds_str = if let Some(ty_param_bounds) = ty_param_bounds_opt {
         let bounds: &[_] = &ty_param_bounds;
-        let bound_str = bounds.iter()
-            .filter_map(|ty_bound| ty_bound.rewrite(context, context.config.max_width, indent))
-            .join(" + ");
+        let bound_str = try_opt!(bounds.iter()
+            .map(|ty_bound| ty_bound.rewrite(context, context.config.max_width, indent))
+            .intersperse(Some(" + ".to_string()))
+            .collect::<Option<String>>());
         if bounds.len() > 0 {
             format!(": {}", bound_str)
         } else {
@@ -1700,9 +1701,10 @@ fn rewrite_trait_bounds(context: &RewriteContext,
         return Some(String::new());
     }
 
-    let bound_str = bounds.iter()
-        .filter_map(|ty_bound| ty_bound.rewrite(&context, width, indent))
-        .join(" + ");
+    let bound_str = try_opt!(bounds.iter()
+        .map(|ty_bound| ty_bound.rewrite(&context, width, indent))
+        .intersperse(Some(" + ".to_string()))
+        .collect::<Option<String>>());
 
     let mut result = String::new();
     result.push_str(": ");
index 0c35c82791f59853526ca2f092c31b6f1f636699..8fa24df0caa27a26bbb44ebe76f7ddad4db9f567 100644 (file)
@@ -326,40 +326,40 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
                 let type_str = try_opt!(bounded_ty.rewrite(context, width, offset));
 
                 if !bound_lifetimes.is_empty() {
-                    let lifetime_str = try_opt!(bound_lifetimes.iter()
+                    let lifetime_str: String = try_opt!(bound_lifetimes.iter()
                                                                .map(|lt| {
                                                                    lt.rewrite(context,
                                                                               width,
                                                                               offset)
                                                                })
                                                                .intersperse(Some(", ".to_string()))
-                                                               .collect::<Option<String>>());
+                                                               .collect());
 
                     // 8 = "for<> : ".len()
                     let used_width = lifetime_str.len() + type_str.len() + 8;
                     let budget = try_opt!(width.checked_sub(used_width));
-                    let bounds_str = try_opt!(bounds.iter()
+                    let bounds_str: String = try_opt!(bounds.iter()
                                                     .map(|ty_bound| {
                                                         ty_bound.rewrite(context,
                                                                          budget,
                                                                          offset + used_width)
                                                     })
                                                     .intersperse(Some(" + ".to_string()))
-                                                    .collect::<Option<String>>());
+                                                    .collect());
 
                     format!("for<{}> {}: {}", lifetime_str, type_str, bounds_str)
                 } else {
                     // 2 = ": ".len()
                     let used_width = type_str.len() + 2;
                     let budget = try_opt!(width.checked_sub(used_width));
-                    let bounds_str = try_opt!(bounds.iter()
+                    let bounds_str: String = try_opt!(bounds.iter()
                                                     .map(|ty_bound| {
                                                         ty_bound.rewrite(context,
                                                                          budget,
                                                                          offset + used_width)
                                                     })
                                                     .intersperse(Some(" + ".to_string()))
-                                                    .collect::<Option<String>>());
+                                                    .collect());
 
                     format!("{}: {}", type_str, bounds_str)
                 }
@@ -451,11 +451,11 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
         if !self.bounds.is_empty() {
             result.push_str(": ");
 
-            let bounds = try_opt!(self.bounds
+            let bounds: String = try_opt!(self.bounds
                 .iter()
                 .map(|ty_bound| ty_bound.rewrite(context, width, offset))
                 .intersperse(Some(" + ".to_string()))
-                .collect::<Option<String>>());
+                .collect());
 
             result.push_str(&bounds);
         }
@@ -478,11 +478,11 @@ fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Opt
 impl Rewrite for ast::PolyTraitRef {
     fn rewrite(&self, context: &RewriteContext, width: usize, offset: Indent) -> Option<String> {
         if !self.bound_lifetimes.is_empty() {
-            let lifetime_str = try_opt!(self.bound_lifetimes
+            let lifetime_str: String = try_opt!(self.bound_lifetimes
                 .iter()
                 .map(|lt| lt.rewrite(context, width, offset))
                 .intersperse(Some(", ".to_string()))
-                .collect::<Option<String>>());
+                .collect());
 
             // 6 is "for<> ".len()
             let extra_offset = lifetime_str.len() + 6;