From: topecongiro Date: Sat, 2 Sep 2017 23:10:12 +0000 (+0900) Subject: Do not allow single-lined closure with block body X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f8bdcd62e8f4087f602018c97063733590367ffe;hp=737186b8901a4c843f5b7eed2f3a9a8a3e41e397;p=rust.git Do not allow single-lined closure with block body --- diff --git a/src/expr.rs b/src/expr.rs index 228722474e1..cc18d8edbac 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -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 { diff --git a/tests/target/chains-visual.rs b/tests/target/chains-visual.rs index 829a27867dd..ef166a2bb66 100644 --- a/tests/target/chains-visual.rs +++ b/tests/target/chains-visual.rs @@ -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 = diff --git a/tests/target/chains.rs b/tests/target/chains.rs index 4955817da5c..2720f51d5f3 100644 --- a/tests/target/chains.rs +++ b/tests/target/chains.rs @@ -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 = diff --git a/tests/target/hard-tabs.rs b/tests/target/hard-tabs.rs index 4ac6df5def8..ecaffc165e6 100644 --- a/tests/target/hard-tabs.rs +++ b/tests/target/hard-tabs.rs @@ -80,7 +80,9 @@ fn generic(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();