X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fclosures.rs;h=fa656cc351eea68c857d6bbe8ce99cdd3acaa384;hb=cbd568083d87a90dfe5ab0e90f404454946c9f20;hp=9546451d7ca9961be3801ee860cf06fae5b41536;hpb=e2b9c66cc9d3228339d07cb5410f6cabdac97de8;p=rust.git diff --git a/src/closures.rs b/src/closures.rs index 9546451d7ca..fa656cc351e 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -13,9 +13,10 @@ use syntax::source_map::Span; use syntax::{ast, ptr}; -use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond, ToExpr}; +use expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond}; use items::{span_hi_for_arg, span_lo_for_arg}; use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; +use overflow::OverflowableItem; use rewrite::{Rewrite, RewriteContext}; use shape::Shape; use source_map::SpanUtils; @@ -344,9 +345,9 @@ pub fn rewrite_last_closure( // 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); } @@ -358,18 +359,12 @@ pub fn rewrite_last_closure( } /// Returns true if the given vector of arguments has more than one `ast::ExprKind::Closure`. -pub fn args_have_many_closure(args: &[&T]) -> bool -where - T: ToExpr, -{ +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