Skip to content

Commit 8be748d

Browse files
ytmimicalebcartwright
authored andcommitted
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 9316df0 commit 8be748d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/expr.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,17 @@ fn rewrite_block(
575575
label: Option<ast::Label>,
576576
context: &RewriteContext<'_>,
577577
shape: Shape,
578+
) -> Option<String> {
579+
rewrite_block_inner(block, attrs, label, true, context, shape)
580+
}
581+
582+
fn rewrite_block_inner(
583+
block: &ast::Block,
584+
attrs: Option<&[ast::Attribute]>,
585+
label: Option<ast::Label>,
586+
allow_single_line: bool,
587+
context: &RewriteContext<'_>,
588+
shape: Shape,
578589
) -> Option<String> {
579590
let prefix = block_prefix(context, block, shape)?;
580591

@@ -586,7 +597,7 @@ fn rewrite_block(
586597

587598
let result = rewrite_block_with_visitor(context, &prefix, block, attrs, label, shape, true);
588599
if let Some(ref result_str) = result {
589-
if result_str.lines().count() <= 3 {
600+
if allow_single_line && result_str.lines().count() <= 3 {
590601
if let rw @ Some(_) =
591602
rewrite_single_line_block(context, &prefix, block, attrs, label, shape)
592603
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy