Fix formatting issue with closures hiding in unary ops

This commit is contained in:
Joshua Warner 2024-12-24 14:38:23 -05:00
parent 8f0566a55f
commit 2464ce6856
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 68 additions and 4 deletions

View file

@ -1313,13 +1313,21 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
after: right_lifted.after,
}
}
Expr::UnaryOp(expr, op) => {
let expr_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &expr.value);
Expr::UnaryOp(inner, op) => {
if parens == Parens::InApply && matches!(inner.without_spaces(), Expr::Closure(..)) {
return Spaces {
before: &[],
item: Expr::ParensAround(arena.alloc(*expr)),
after: &[],
};
}
let inner_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &inner.value);
Spaces {
before: &[],
item: Expr::UnaryOp(arena.alloc(Loc::at(expr.region, expr_lifted.item)), *op),
after: expr_lifted.after,
item: Expr::UnaryOp(arena.alloc(Loc::at(inner.region, inner_lifted.item)), *op),
after: inner_lifted.after,
}
}