diff options
| -rw-r--r-- | src/expr.rs | 10 | ||||
| -rw-r--r-- | src/items.rs | 11 |
2 files changed, 19 insertions, 2 deletions
diff --git a/src/expr.rs b/src/expr.rs index eadaf206781..a4e60659a0e 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -609,6 +609,16 @@ fn rewrite_block_inner( result } +/// Rewrite the divergent block of a `let-else` statement. +pub(crate) fn rewrite_let_else_block( + block: &ast::Block, + allow_single_line: bool, + context: &RewriteContext<'_>, + shape: Shape, +) -> Option<String> { + rewrite_block_inner(block, None, None, allow_single_line, context, shape) +} + // Rewrite condition if the given expression has one. pub(crate) fn rewrite_cond( context: &RewriteContext<'_>, diff --git a/src/items.rs b/src/items.rs index 75c42605ccf..4693e57b8a1 100644 --- a/src/items.rs +++ b/src/items.rs @@ -18,7 +18,8 @@ use crate::config::lists::*; use crate::config::{BraceStyle, Config, IndentStyle, Version}; use crate::expr::{ is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with, - rewrite_assign_rhs_with_comments, rewrite_else_kw_with_comments, RhsAssignKind, RhsTactics, + rewrite_assign_rhs_with_comments, rewrite_else_kw_with_comments, rewrite_let_else_block, + RhsAssignKind, RhsTactics, }; use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; use crate::macros::{rewrite_macro, MacroPosition}; @@ -132,7 +133,13 @@ impl Rewrite for ast::Local { shape, ); result.push_str(&else_kw); - result.push_str(&block.rewrite(context, shape)?); + let allow_single_line = !result.contains('\n'); + result.push_str(&rewrite_let_else_block( + block, + allow_single_line, + context, + shape, + )?); }; } |
