take_source_hints: bool, true, "Retain some formatting characteristics from the source code";
hard_tabs: bool, false, "Use tab characters for indentation, spaces for alignment";
wrap_comments: bool, false, "Break comments to fit on the line";
+ wrap_match_arms: bool, true, "Wrap multiline match arms in blocks";
}
}
let body = match **body {
- ast::Expr { node: ast::ExprBlock(ref b), .. } if !is_unsafe_block(b) &&
- is_simple_block(b,
- context.codemap) => {
- b.expr.as_ref().map(|e| &**e).unwrap()
+ ast::Expr { node: ast::ExprBlock(ref block), .. } if !is_unsafe_block(block) &&
+ is_simple_block(block,
+ context.codemap) &&
+ context.config.wrap_match_arms => {
+ block.expr.as_ref().map(|e| &**e).unwrap()
}
ref x => x,
};
let rewrite = nop_block_collapse(body.rewrite(context, budget, offset), budget);
match rewrite {
- Some(ref body_str) if !body_str.contains('\n') || comma.is_empty() => {
+ Some(ref body_str) if !body_str.contains('\n') || !context.config.wrap_match_arms ||
+ comma.is_empty() => {
return Some(format!("{}{} => {}{}",
attr_str.trim_left(),
pats_str,
}
}
- // FIXME: we're doing a second rewrite of the expr -- this may not be
+ // FIXME: we're doing a second rewrite of the expr; This may not be
// necessary.
let body_budget = try_opt!(width.checked_sub(context.config.tab_spaces));
let indent = context.block_indent.block_indent(context.config);
indent),
body_budget));
let indent_str = offset.block_indent(context.config).to_string(context.config);
+ let (body_prefix, body_suffix) = if context.config.wrap_match_arms {
+ (" {", "}")
+ } else {
+ ("", "")
+ };
- Some(format!("{}{} => {{\n{}{}\n{}}}",
+ Some(format!("{}{} =>{}\n{}{}\n{}{}",
attr_str.trim_left(),
pats_str,
+ body_prefix,
indent_str,
next_line_body,
- offset.to_string(context.config)))
+ offset.to_string(context.config),
+ body_suffix))
}
}
--- /dev/null
+// rustfmt-wrap_match_arms: false
+// Match expressions, no unwrapping of block arms or wrapping of multiline
+// expressions.
+
+fn foo() {
+ match x {
+ a => { foo() }
+ b =>
+ (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
+ }
+}
--- /dev/null
+// rustfmt-wrap_match_arms: false
+// Match expressions, no unwrapping of block arms or wrapping of multiline
+// expressions.
+
+fn foo() {
+ match x {
+ a => {
+ foo()
+ }
+ b => (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
+ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
+ }
+}