]> git.lizzy.rs Git - rust.git/commitdiff
Disallow overflowing closure if there are multiple closures in args
authortopecongiro <seuchida@gmail.com>
Mon, 19 Jun 2017 03:07:20 +0000 (12:07 +0900)
committertopecongiro <seuchida@gmail.com>
Mon, 19 Jun 2017 03:07:20 +0000 (12:07 +0900)
src/expr.rs
tests/source/closure.rs
tests/target/closure.rs

index 8ff06f650ebd20b748aa53095acacb6de8b8f1fc..6546afd2d6394b1b21b2072b0140eafcb62f1af1 100644 (file)
@@ -2155,7 +2155,7 @@ fn try_overflow_last_arg<'a, T>(
             .map_or((None, None), |arg_shape| {
                 rewrite_last_arg_with_overflow(
                     &context,
-                    args[args.len() - 1],
+                    args,
                     &mut item_vec[args.len() - 1],
                     arg_shape,
                 )
@@ -2251,18 +2251,35 @@ fn rewrite_last_closure(
 
 fn rewrite_last_arg_with_overflow<'a, T>(
     context: &RewriteContext,
-    last_arg: &T,
+    args: &[&T],
     last_item: &mut ListItem,
     shape: Shape,
 ) -> (Option<String>, Option<String>)
 where
     T: Rewrite + Spanned + ToExpr + 'a,
 {
+    let last_arg = args[args.len() - 1];
     let rewrite = if let Some(expr) = last_arg.to_expr() {
         match expr.node {
             // When overflowing the closure which consists of a single control flow expression,
             // force to use block if its condition uses multi line.
-            ast::ExprKind::Closure(..) => rewrite_last_closure(context, expr, shape),
+            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,
+                        }) {
+                    None
+                } else {
+                    rewrite_last_closure(context, expr, shape)
+                }
+            }
             _ => expr.rewrite(context, shape),
         }
     } else {
index b52643f2fb8c6a0a3dbd561799405044d8f5ac72..e1aa8fc345e49da2910316cf7da5bbf606a29859 100644 (file)
@@ -151,3 +151,17 @@ fn issue1697() {
 fn issue1694() {
     foooooo(|_referencefffffffff: _, _target_reference: _, _oid: _, _target_oid: _| format!("refs/pull/{}/merge", pr_id))
 }
+
+fn issue1713() {
+    rayon::join(
+        || recurse(left, is_less, pred, limit),
+        || recurse(right, is_less, Some(pivot), limit),
+    );
+
+    rayon::join(
+        1,
+        || recurse(left, is_less, pred, limit),
+        2,
+        || recurse(right, is_less, Some(pivot), limit),
+    );
+}
index 3d6d322a1039b24667fad3e3ae011bb2dd644b84..bb31cad792b6a17bf798fbf23c578b69758436fb 100644 (file)
@@ -182,3 +182,17 @@ fn issue1694() {
         },
     )
 }
+
+fn issue1713() {
+    rayon::join(
+        || recurse(left, is_less, pred, limit),
+        || recurse(right, is_less, Some(pivot), limit),
+    );
+
+    rayon::join(
+        1,
+        || recurse(left, is_less, pred, limit),
+        2,
+        || recurse(right, is_less, Some(pivot), limit),
+    );
+}