Fix comments in when conditionals

This commit is contained in:
Richard Feldman 2022-07-06 16:36:35 -04:00
parent f01d6a55f7
commit 18edf5f0d6
No known key found for this signature in database
GPG key ID: 7E4127D1E4241798

View file

@ -656,11 +656,22 @@ fn fmt_when<'a, 'buf>(
buf.newline();
match &expr_below {
Expr::SpaceAfter(expr_above, spaces_below_expr) => {
// If any of the spaces is a newline, add a newline at the top.
// Otherwise leave it as just a comment.
let newline_at = if spaces_below_expr
.iter()
.any(|spaces| matches!(spaces, CommentOrNewline::Newline))
{
NewlineAt::Top
} else {
NewlineAt::None
};
expr_above.format(buf, condition_indent);
fmt_comments_only(
buf,
spaces_below_expr.iter(),
NewlineAt::Top,
newline_at,
condition_indent,
);
buf.newline();