Skip to content

Commit 81cd12c

Browse files
committed
Add args_have_many_closure()
1 parent 49409c0 commit 81cd12c

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/expr.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2281,15 +2281,7 @@ where
22812281
ast::ExprKind::Closure(..) => {
22822282
// If the argument consists of multiple closures, we do not overflow
22832283
// the last closure.
2284-
if args.len() > 1
2285-
&& args.iter()
2286-
.rev()
2287-
.skip(1)
2288-
.filter_map(|arg| arg.to_expr())
2289-
.any(|expr| match expr.node {
2290-
ast::ExprKind::Closure(..) => true,
2291-
_ => false,
2292-
}) {
2284+
if args_have_many_closure(args) {
22932285
None
22942286
} else {
22952287
rewrite_last_closure(context, expr, shape)
@@ -2310,6 +2302,22 @@ where
23102302
}
23112303
}
23122304

2305+
fn args_have_many_closure<T>(args: &[&T]) -> bool
2306+
where
2307+
T: ToExpr,
2308+
{
2309+
args.iter()
2310+
.filter(|arg| {
2311+
arg.to_expr()
2312+
.map(|e| match e.node {
2313+
ast::ExprKind::Closure(..) => true,
2314+
_ => false,
2315+
})
2316+
.unwrap_or(false)
2317+
})
2318+
.count() > 1
2319+
}
2320+
23132321
fn can_be_overflowed<'a, T>(context: &RewriteContext, args: &[&T]) -> bool
23142322
where
23152323
T: Rewrite + Spanned + ToExpr + 'a,

0 commit comments

Comments
 (0)