Do not allow single-lined closure with block body

This commit is contained in:
topecongiro 2017-09-03 08:10:12 +09:00
parent 737186b890
commit f8bdcd62e8
4 changed files with 10 additions and 16 deletions

View 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 {

View 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 =

View 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 =

View file

@ -80,7 +80,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);
});
});
a.b.c.d();