Skip to content

Commit 8deca25

Browse files
Make sure to add parens if a PncApply dbg stmt becomes a space-separated Apply
1 parent 0438c17 commit 8deca25

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

crates/compiler/fmt/src/expr.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,16 @@ pub fn expr_lift_spaces<'a, 'b: 'a>(
13401340

13411341
let right_lifted = expr_lift_spaces_after(Parens::InOperator, arena, &right.value);
13421342

1343+
let mut item =
1344+
Expr::BinOps(lefts, arena.alloc(Loc::at(right.region, right_lifted.item)));
1345+
1346+
if parens == Parens::InApply || parens == Parens::InApplyLastArg {
1347+
item = Expr::ParensAround(arena.alloc(item));
1348+
}
1349+
13431350
Spaces {
13441351
before,
1345-
item: Expr::BinOps(lefts, arena.alloc(Loc::at(right.region, right_lifted.item))),
1352+
item,
13461353
after: right_lifted.after,
13471354
}
13481355
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dbg (a / a)
2+
d
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@0-8 SpaceAfter(
2+
DbgStmt {
3+
first: @4-7 BinOps(
4+
[
5+
(
6+
@4-5 Var {
7+
module_name: "",
8+
ident: "a",
9+
},
10+
@5-6 Slash,
11+
),
12+
],
13+
@6-7 Var {
14+
module_name: "",
15+
ident: "a",
16+
},
17+
),
18+
extra_args: [],
19+
continuation: @9-10 SpaceBefore(
20+
Var {
21+
module_name: "",
22+
ident: "d",
23+
},
24+
[
25+
Newline,
26+
],
27+
),
28+
},
29+
[
30+
Newline,
31+
],
32+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dbg(a/a)
2+
d

crates/compiler/test_syntax/tests/test_snapshots.rs

+1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ mod test_snapshots {
397397
pass/dbg_double_newline.expr,
398398
pass/dbg_extra_parens.expr,
399399
pass/dbg_newline_apply.expr,
400+
pass/dbg_pnc_a_over_a.expr,
400401
pass/dbg_stmt.expr,
401402
pass/dbg_stmt_in_parens.expr,
402403
pass/dbg_stmt_multiline.expr,

0 commit comments

Comments
 (0)