Make sure to add parens if a PncApply dbg stmt becomes a space-separated Apply

This commit is contained in:
Joshua Warner 2025-01-09 18:36:00 -08:00
parent 0438c17503
commit 8deca25c5e
No known key found for this signature in database
GPG key ID: 89AD497003F93FDD
5 changed files with 45 additions and 1 deletions

View file

@ -1340,9 +1340,16 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
let right_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &right.value); let right_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &right.value);
let mut item =
Expr::BinOps(lefts, arena.alloc(Loc::at(right.region, right_lifted.item)));
if parens == Parens::InApply || parens == Parens::InApplyLastArg {
item = Expr::ParensAround(arena.alloc(item));
}
Spaces { Spaces {
before, before,
item: Expr::BinOps(lefts, arena.alloc(Loc::at(right.region, right_lifted.item))), item,
after: right_lifted.after, after: right_lifted.after,
} }
} }

View file

@ -0,0 +1,2 @@
dbg (a / a)
d

View file

@ -0,0 +1,32 @@
@0-8 SpaceAfter(
DbgStmt {
first: @4-7 BinOps(
[
(
@4-5 Var {
module_name: "",
ident: "a",
},
@5-6 Slash,
),
],
@6-7 Var {
module_name: "",
ident: "a",
},
),
extra_args: [],
continuation: @9-10 SpaceBefore(
Var {
module_name: "",
ident: "d",
},
[
Newline,
],
),
},
[
Newline,
],
)

View file

@ -0,0 +1,2 @@
dbg(a/a)
d

View file

@ -397,6 +397,7 @@ mod test_snapshots {
pass/dbg_double_newline.expr, pass/dbg_double_newline.expr,
pass/dbg_extra_parens.expr, pass/dbg_extra_parens.expr,
pass/dbg_newline_apply.expr, pass/dbg_newline_apply.expr,
pass/dbg_pnc_a_over_a.expr,
pass/dbg_stmt.expr, pass/dbg_stmt.expr,
pass/dbg_stmt_in_parens.expr, pass/dbg_stmt_in_parens.expr,
pass/dbg_stmt_multiline.expr, pass/dbg_stmt_multiline.expr,