]> git.lizzy.rs Git - rust.git/commitdiff
Do not allow single-lined closure with block body
authortopecongiro <seuchida@gmail.com>
Sat, 2 Sep 2017 23:10:12 +0000 (08:10 +0900)
committertopecongiro <seuchida@gmail.com>
Sat, 2 Sep 2017 23:10:12 +0000 (08:10 +0900)
src/expr.rs
tests/target/chains-visual.rs
tests/target/chains.rs
tests/target/hard-tabs.rs

index 228722474e1b8706d6aead24912a92b87367c41f..cc18d8edbacd54d58b4df675a723945bc2f11d25 100644 (file)
@@ -630,7 +630,7 @@ fn rewrite_closure(
             false
         };
         if no_return_type && !needs_block {
-            // lock.stmts.len() == 1
+            // block.stmts.len() == 1
             if let Some(expr) = stmt_expr(&block.stmts[0]) {
                 if let Some(rw) = rewrite_closure_expr(expr, &prefix, context, body_shape) {
                     return Some(rw);
@@ -638,18 +638,6 @@ fn rewrite_closure(
             }
         }
 
-        if !needs_block {
-            // We need braces, but we might still prefer a one-liner.
-            let stmt = &block.stmts[0];
-            // 4 = braces and spaces.
-            if let Some(body_shape) = body_shape.sub_width(4) {
-                // Checks if rewrite succeeded and fits on a single line.
-                if let Some(rewrite) = and_one_line(stmt.rewrite(context, body_shape)) {
-                    return Some(format!("{} {{ {} }}", prefix, rewrite));
-                }
-            }
-        }
-
         // Either we require a block, or tried without and failed.
         rewrite_closure_block(block, &prefix, context, body_shape)
     } else {
index 829a27867dd510b3f49580b282c9646e45a5dca2..ef166a2bb66c622fe1b68b94c13723cca141f709 100644 (file)
@@ -42,7 +42,9 @@ fn main() {
     });
 
     fffffffffffffffffffffffffffffffffff(a, {
-        SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
+        SCRIPT_TASK_ROOT.with(|root| {
+            *root.borrow_mut() = Some(&script_task);
+        });
     });
 
     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
index 4955817da5c9c3f9480e597b794586759dfd7487..2720f51d5f3078c57d58d465e7fdc9921861ff18 100644 (file)
@@ -45,7 +45,9 @@ fn main() {
         });
 
     fffffffffffffffffffffffffffffffffff(a, {
-        SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
+        SCRIPT_TASK_ROOT.with(|root| {
+            *root.borrow_mut() = Some(&script_task);
+        });
     });
 
     let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
index 4ac6df5def85dee9455643d9c575ddc345d0d269..ecaffc165e6d2973fb6bfc5bc9584132f072166b 100644 (file)
@@ -80,7 +80,9 @@ fn generic<T>(arg: T) -> &SomeType
        });
 
        fffffffffffffffffffffffffffffffffff(a, {
-               SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
+               SCRIPT_TASK_ROOT.with(|root| {
+                       *root.borrow_mut() = Some(&script_task);
+               });
        });
        a.b.c.d();