]> git.lizzy.rs Git - rust.git/commitdiff
Add args_have_many_closure()
authortopecongiro <seuchida@gmail.com>
Thu, 2 Nov 2017 12:41:46 +0000 (21:41 +0900)
committertopecongiro <seuchida@gmail.com>
Thu, 2 Nov 2017 12:41:46 +0000 (21:41 +0900)
src/expr.rs

index bb3f5e08c2c1b1cfea181a7430d430df90df4f4b..2c56257026514f7e7c54f5391577d918e37d7f33 100644 (file)
@@ -2281,15 +2281,7 @@ fn rewrite_last_arg_with_overflow<'a, T>(
             ast::ExprKind::Closure(..) => {
                 // If the argument consists of multiple closures, we do not overflow
                 // the last closure.
-                if args.len() > 1
-                    && args.iter()
-                        .rev()
-                        .skip(1)
-                        .filter_map(|arg| arg.to_expr())
-                        .any(|expr| match expr.node {
-                            ast::ExprKind::Closure(..) => true,
-                            _ => false,
-                        }) {
+                if args_have_many_closure(args) {
                     None
                 } else {
                     rewrite_last_closure(context, expr, shape)
@@ -2310,6 +2302,22 @@ fn rewrite_last_arg_with_overflow<'a, T>(
     }
 }
 
+fn args_have_many_closure<T>(args: &[&T]) -> bool
+where
+    T: ToExpr,
+{
+    args.iter()
+        .filter(|arg| {
+            arg.to_expr()
+                .map(|e| match e.node {
+                    ast::ExprKind::Closure(..) => true,
+                    _ => false,
+                })
+                .unwrap_or(false)
+        })
+        .count() > 1
+}
+
 fn can_be_overflowed<'a, T>(context: &RewriteContext, args: &[&T]) -> bool
 where
     T: Rewrite + Spanned + ToExpr + 'a,