Simplify some branch formatting logic

This commit is contained in:
Richard Feldman 2022-07-13 22:55:41 -04:00
parent fa877e4184
commit b51c8b0ba4
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -700,13 +700,11 @@ fn fmt_when<'a, 'buf>(
for (pattern_index, pattern) in patterns.iter().enumerate() { for (pattern_index, pattern) in patterns.iter().enumerate() {
if pattern_index == 0 { if pattern_index == 0 {
match &pattern.value { if let Pattern::SpaceBefore(sub_pattern, spaces) = &pattern.value {
Pattern::SpaceBefore(sub_pattern, spaces) => {
let added_blank_line; let added_blank_line;
if branch_index > 0 // Never render newlines before the first branch. // Never render newlines before the first branch.
&& matches!(spaces.first(), Some(CommentOrNewline::Newline)) if branch_index > 0 {
{
if prev_branch_was_multiline { if prev_branch_was_multiline {
// Multiline branches always get a full blank line after them. // Multiline branches always get a full blank line after them.
buf.ensure_ends_with_blank_line(); buf.ensure_ends_with_blank_line();
@ -734,8 +732,7 @@ fn fmt_when<'a, 'buf>(
} }
fmt_pattern(buf, sub_pattern, indent + INDENT, Parens::NotNeeded); fmt_pattern(buf, sub_pattern, indent + INDENT, Parens::NotNeeded);
} } else {
other => {
if branch_index > 0 { if branch_index > 0 {
if prev_branch_was_multiline { if prev_branch_was_multiline {
// Multiline branches always get a full blank line after them. // Multiline branches always get a full blank line after them.
@ -745,8 +742,7 @@ fn fmt_when<'a, 'buf>(
} }
} }
fmt_pattern(buf, other, indent + INDENT, Parens::NotNeeded); fmt_pattern(buf, &pattern.value, indent + INDENT, Parens::NotNeeded);
}
} }
} else { } else {
if is_multiline_patterns { if is_multiline_patterns {