use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
use source_map::SpanUtils;
-use utils::{last_line_width, left_most_sub_expr, stmt_expr};
+use utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
// This module is pretty messy because of the rules around closures and blocks:
// FIXME - the below is probably no longer true in full.
let block = ast::Block {
stmts: vec![ast::Stmt {
- id: ast::NodeId::new(0),
+ id: ast::NodeId::root(),
node: ast::StmtKind::Expr(ptr::P(body.clone())),
span: body.span,
}],
- id: ast::NodeId::new(0),
+ id: ast::NodeId::root(),
rules: ast::BlockCheckMode::Default,
span: body.span,
recovered: false,
// When overflowing the closure which consists of a single control flow expression,
// force to use block if its condition uses multi line.
- let is_multi_lined_cond = rewrite_cond(context, body, body_shape)
- .map(|cond| cond.contains('\n') || cond.len() > body_shape.width)
- .unwrap_or(false);
+ let is_multi_lined_cond = rewrite_cond(context, body, body_shape).map_or(false, |cond| {
+ cond.contains('\n') || cond.len() > body_shape.width
+ });
if is_multi_lined_cond {
return rewrite_closure_with_block(body, &prefix, context, body_shape);
}
/// Returns true if the given vector of arguments has more than one `ast::ExprKind::Closure`.
pub fn args_have_many_closure(args: &[OverflowableItem]) -> bool {
args.iter()
- .filter(|arg| {
- arg.to_expr()
- .map(|e| match e.node {
- ast::ExprKind::Closure(..) => true,
- _ => false,
- })
- .unwrap_or(false)
+ .filter_map(|arg| arg.to_expr())
+ .filter(|expr| match expr.node {
+ ast::ExprKind::Closure(..) => true,
+ _ => false,
})
.count()
> 1