about summary refs log tree commit diff
path: root/src/patterns.rs
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2016-02-15 10:07:19 +1300
committerNick Cameron <ncameron@mozilla.com>2016-02-15 10:07:19 +1300
commit160eb73baab57cbe0dbb221f5220fc4475ccd1da (patch)
tree5f11bb5b1f22e991c25885235cca6a9ba3fbd480 /src/patterns.rs
parentd86cfb357aef2d70e67e616f60ca587bd12def62 (diff)
reviewer changes
Diffstat (limited to 'src/patterns.rs')
-rw-r--r--src/patterns.rs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/patterns.rs b/src/patterns.rs
index 1aee4ae7a21..a5f09823212 100644
--- a/src/patterns.rs
+++ b/src/patterns.rs
@@ -31,8 +31,10 @@ impl Rewrite for Pat {
 
                 let sub_pat = match *sub_pat {
                     Some(ref p) => {
+                        // 3 - ` @ `.
                         let width = try_opt!(width.checked_sub(prefix.len() + mut_infix.len() +
-                                                               id_str.len()));
+                                                               id_str.len() +
+                                                               3));
                         format!(" @ {}", try_opt!(p.rewrite(context, width, offset)))
                     }
                     None => "".to_owned(),
@@ -105,17 +107,16 @@ impl Rewrite for Pat {
                 let suffix = suffix.iter().map(|p| p.rewrite(context, width, offset));
 
                 // Munge them together.
-                let pats = prefix.chain(slice_pat.into_iter()).chain(suffix);
+                let pats: Option<Vec<String>> = prefix.chain(slice_pat.into_iter())
+                                                      .chain(suffix)
+                                                      .collect();
 
                 // Check that all the rewrites succeeded, and if not return None.
-                let (somes, nones) = pats.partition::<Vec<Option<String>>, _>(Option::is_some);
-                if nones.len() > 0 {
-                    return None;
-                }
+                let pats = try_opt!(pats);
 
                 // Unwrap all the sub-strings and join them with commas.
-                let pats = somes.into_iter().map(|p| p.unwrap()).collect::<Vec<_>>().join(", ");
-                Some(format!("[{}]", pats))
+                let result = format!("[{}]", pats.join(", "));
+                wrap_str(result, context.config.max_width, width, offset)
             }
             Pat_::PatStruct(ref path, ref fields, elipses) => {
                 let path = try_opt!(rewrite_path(context, true, None, path, width, offset));
@@ -126,10 +127,12 @@ impl Rewrite for Pat {
                     ("", "}")
                 };
 
+                // 5 = `{` plus space before and after plus `}` plus space before.
                 let budget = try_opt!(width.checked_sub(path.len() + 5 + elipses_str.len()));
                 // FIXME Using visual indenting, should use block or visual to match
                 // struct lit preference (however, in practice I think it is rare
                 // for struct patterns to be multi-line).
+                // 3 = `{` plus space before and after.
                 let offset = offset + path.len() + 3;
 
                 let items = itemize_list(context.codemap,
@@ -157,7 +160,7 @@ impl Rewrite for Pat {
                     }
                 }
 
-                if field_string.len() == 0 {
+                if field_string.is_empty() {
                     Some(format!("{} {{}}", path))
                 } else {
                     Some(format!("{} {{ {} }}", path, field_string))
@@ -180,7 +183,10 @@ impl Rewrite for FieldPat {
         if self.is_shorthand {
             pat
         } else {
-            Some(format!("{}: {}", self.ident.to_string(), try_opt!(pat)))
+            wrap_str(format!("{}: {}", self.ident.to_string(), try_opt!(pat)),
+                     context.config.max_width,
+                     width,
+                     offset)
         }
     }
 }