|| prefix.contains('\n')
}
+fn veto_block(e: &ast::Expr) -> bool {
+ match e.node {
+ ast::ExprKind::Call(..)
+ | ast::ExprKind::Binary(..)
+ | ast::ExprKind::Cast(..)
+ | ast::ExprKind::Type(..)
+ | ast::ExprKind::Assign(..)
+ | ast::ExprKind::AssignOp(..)
+ | ast::ExprKind::Field(..)
+ | ast::ExprKind::Index(..)
+ | ast::ExprKind::Range(..)
+ | ast::ExprKind::Try(..) => true,
+ _ => false,
+ }
+}
+
// Rewrite closure with a single expression wrapping its body with block.
fn rewrite_closure_with_block(
body: &ast::Expr,
shape: Shape,
) -> Option<String> {
let left_most = left_most_sub_expr(body);
- let veto_block = left_most != body && !classify::expr_requires_semi_to_be_stmt(left_most);
+ let veto_block = veto_block(body) && !classify::expr_requires_semi_to_be_stmt(left_most);
if veto_block {
return None;
}
} else {
Some(rw)
}
- })
- .map(|rw| format!("{} {}", prefix, rw))
+ }).map(|rw| format!("{} {}", prefix, rw))
}
// Rewrite closure whose body is block.
_ => arg_shape,
};
- let fmt = ListFormatting {
- tactic,
- separator: ",",
- trailing_separator: SeparatorTactic::Never,
- separator_place: SeparatorPlace::Back,
- shape: arg_shape,
- ends_with_newline: false,
- preserve_newline: true,
- nested: false,
- config: context.config,
- };
+ let fmt = ListFormatting::new(arg_shape, context.config)
+ .tactic(tactic)
+ .preserve_newline(true);
let list_str = write_list(&item_vec, &fmt)?;
let mut prefix = format!("{}{}{}|{}|", is_async, immovable, mover, list_str);
.map(|e| match e.node {
ast::ExprKind::Closure(..) => true,
_ => false,
- })
- .unwrap_or(false)
- })
- .count()
+ }).unwrap_or(false)
+ }).count()
> 1
}