Cargo fmt

This commit is contained in:
Seiichi Uchida 2017-12-10 21:54:26 +09:00
parent 90383d7426
commit e3d2f2c2b1
3 changed files with 22 additions and 15 deletions

View File

@ -419,10 +419,12 @@ fn rewrite_chain_subexpr(
context: &RewriteContext,
shape: Shape,
) -> Option<String> {
let rewrite_element = |expr_str: String| if expr_str.len() <= shape.width {
Some(expr_str)
} else {
None
let rewrite_element = |expr_str: String| {
if expr_str.len() <= shape.width {
Some(expr_str)
} else {
None
}
};
match expr.node {

View File

@ -2316,12 +2316,13 @@ fn rewrite_paren(context: &RewriteContext, subexpr: &ast::Expr, shape: Shape) ->
.offset_left(paren_overhead)
.and_then(|s| s.sub_width(paren_overhead))?;
let paren_wrapper =
|s: &str| if context.config.spaces_within_parens_and_brackets() && !s.is_empty() {
let paren_wrapper = |s: &str| {
if context.config.spaces_within_parens_and_brackets() && !s.is_empty() {
format!("( {} )", s)
} else {
format!("({})", s)
};
}
};
let subexpr_str = subexpr.rewrite(context, sub_shape)?;
debug!("rewrite_paren, subexpr_str: `{:?}`", subexpr_str);

View File

@ -482,10 +482,12 @@ impl<'a> FmtVisitor<'a> {
enum_def.variants.iter(),
"}",
",",
|f| if !f.node.attrs.is_empty() {
f.node.attrs[0].span.lo()
} else {
f.span.lo()
|f| {
if !f.node.attrs.is_empty() {
f.node.attrs[0].span.lo()
} else {
f.span.lo()
}
},
|f| f.span.hi(),
|f| self.format_variant(f, one_line_width),
@ -2549,10 +2551,12 @@ fn rewrite_where_clause_rfc_style(
};
let preds_str = write_list(&items.collect::<Vec<_>>(), &fmt)?;
let comment_separator = |comment: &str, shape: Shape| if comment.is_empty() {
String::new()
} else {
format!("\n{}", shape.indent.to_string(context.config))
let comment_separator = |comment: &str, shape: Shape| {
if comment.is_empty() {
String::new()
} else {
format!("\n{}", shape.indent.to_string(context.config))
}
};
let newline_before_where = comment_separator(&comment_before, shape);
let newline_after_where = comment_separator(&comment_after, clause_shape);