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