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.
This commit is contained in:
Yacin Tmimi 2023-02-12 14:31:38 -05:00 committed by Caleb Cartwright
parent 9316df0ca2
commit 8be748dbb7

View File

@ -575,6 +575,17 @@ fn rewrite_block(
label: Option<ast::Label>,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
rewrite_block_inner(block, attrs, label, true, context, shape)
}
fn rewrite_block_inner(
block: &ast::Block,
attrs: Option<&[ast::Attribute]>,
label: Option<ast::Label>,
allow_single_line: bool,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
let prefix = block_prefix(context, block, shape)?;
@ -586,7 +597,7 @@ fn rewrite_block(
let result = rewrite_block_with_visitor(context, &prefix, block, attrs, label, shape, true);
if let Some(ref result_str) = result {
if result_str.lines().count() <= 3 {
if allow_single_line && result_str.lines().count() <= 3 {
if let rw @ Some(_) =
rewrite_single_line_block(context, &prefix, block, attrs, label, shape)
{