Skip to content

Commit 160eb73

Browse files
committed
reviewer changes
1 parent d86cfb3 commit 160eb73

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

src/patterns.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ impl Rewrite for Pat {
3131

3232
let sub_pat = match *sub_pat {
3333
Some(ref p) => {
34+
// 3 - ` @ `.
3435
let width = try_opt!(width.checked_sub(prefix.len() + mut_infix.len() +
35-
id_str.len()));
36+
id_str.len() +
37+
3));
3638
format!(" @ {}", try_opt!(p.rewrite(context, width, offset)))
3739
}
3840
None => "".to_owned(),
@@ -105,17 +107,16 @@ impl Rewrite for Pat {
105107
let suffix = suffix.iter().map(|p| p.rewrite(context, width, offset));
106108

107109
// Munge them together.
108-
let pats = prefix.chain(slice_pat.into_iter()).chain(suffix);
110+
let pats: Option<Vec<String>> = prefix.chain(slice_pat.into_iter())
111+
.chain(suffix)
112+
.collect();
109113

110114
// Check that all the rewrites succeeded, and if not return None.
111-
let (somes, nones) = pats.partition::<Vec<Option<String>>, _>(Option::is_some);
112-
if nones.len() > 0 {
113-
return None;
114-
}
115+
let pats = try_opt!(pats);
115116

116117
// Unwrap all the sub-strings and join them with commas.
117-
let pats = somes.into_iter().map(|p| p.unwrap()).collect::<Vec<_>>().join(", ");
118-
Some(format!("[{}]", pats))
118+
let result = format!("[{}]", pats.join(", "));
119+
wrap_str(result, context.config.max_width, width, offset)
119120
}
120121
Pat_::PatStruct(ref path, ref fields, elipses) => {
121122
let path = try_opt!(rewrite_path(context, true, None, path, width, offset));
@@ -126,10 +127,12 @@ impl Rewrite for Pat {
126127
("", "}")
127128
};
128129

130+
// 5 = `{` plus space before and after plus `}` plus space before.
129131
let budget = try_opt!(width.checked_sub(path.len() + 5 + elipses_str.len()));
130132
// FIXME Using visual indenting, should use block or visual to match
131133
// struct lit preference (however, in practice I think it is rare
132134
// for struct patterns to be multi-line).
135+
// 3 = `{` plus space before and after.
133136
let offset = offset + path.len() + 3;
134137

135138
let items = itemize_list(context.codemap,
@@ -157,7 +160,7 @@ impl Rewrite for Pat {
157160
}
158161
}
159162

160-
if field_string.len() == 0 {
163+
if field_string.is_empty() {
161164
Some(format!("{} {{}}", path))
162165
} else {
163166
Some(format!("{} {{ {} }}", path, field_string))
@@ -180,7 +183,10 @@ impl Rewrite for FieldPat {
180183
if self.is_shorthand {
181184
pat
182185
} else {
183-
Some(format!("{}: {}", self.ident.to_string(), try_opt!(pat)))
186+
wrap_str(format!("{}: {}", self.ident.to_string(), try_opt!(pat)),
187+
context.config.max_width,
188+
width,
189+
offset)
184190
}
185191
}
186192
}

0 commit comments

Comments
 (0)