Skip to content

Commit b91ed2e

Browse files
committed
Allow callers to determine if blocks can be formatted on a single line
This will make it easier to format the divergent blocks of `let-else` statements since it'll be easier to prevent the block from being formatted on a single line if the preconditions aren't met.
1 parent e221689 commit b91ed2e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: src/expr.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,17 @@ fn rewrite_block(
571571
label: Option<ast::Label>,
572572
context: &RewriteContext<'_>,
573573
shape: Shape,
574+
) -> Option<String> {
575+
rewrite_block_inner(block, attrs, label, true, context, shape)
576+
}
577+
578+
fn rewrite_block_inner(
579+
block: &ast::Block,
580+
attrs: Option<&[ast::Attribute]>,
581+
label: Option<ast::Label>,
582+
allow_single_line: bool,
583+
context: &RewriteContext<'_>,
584+
shape: Shape,
574585
) -> Option<String> {
575586
let prefix = block_prefix(context, block, shape)?;
576587

@@ -582,7 +593,7 @@ fn rewrite_block(
582593

583594
let result = rewrite_block_with_visitor(context, &prefix, block, attrs, label, shape, true);
584595
if let Some(ref result_str) = result {
585-
if result_str.lines().count() <= 3 {
596+
if allow_single_line && result_str.lines().count() <= 3 {
586597
if let rw @ Some(_) =
587598
rewrite_single_line_block(context, &prefix, block, attrs, label, shape)
588599
{

0 commit comments

Comments
 (0)