mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-07 14:13:47 +00:00
Verify whether adding block is safe in rewrite_closure_with_block()
Also ensure that the expression is nested to avoid false-positive.
This commit is contained in:
parent
4110c7b8c5
commit
5871967312
@ -118,6 +118,12 @@ fn rewrite_closure_with_block(
|
||||
context: &RewriteContext,
|
||||
shape: Shape,
|
||||
) -> Option<String> {
|
||||
let left_most = left_most_sub_expr(body);
|
||||
let veto_block = left_most != body && !classify::expr_requires_semi_to_be_stmt(left_most);
|
||||
if veto_block {
|
||||
return None;
|
||||
}
|
||||
|
||||
let block = ast::Block {
|
||||
stmts: vec![
|
||||
ast::Stmt {
|
||||
@ -142,9 +148,6 @@ fn rewrite_closure_expr(
|
||||
shape: Shape,
|
||||
) -> Option<String> {
|
||||
let mut rewrite = expr.rewrite(context, shape);
|
||||
if classify::expr_requires_semi_to_be_stmt(left_most_sub_expr(expr)) {
|
||||
rewrite = and_one_line(rewrite);
|
||||
}
|
||||
rewrite = rewrite.and_then(|rw| {
|
||||
if context.config.force_multiline_blocks() && rw.contains('\n') {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user