Skip to content

Commit b3cc7cf

Browse files
committed
Fix underflows when formatting certain call chains
For certain call chains the formatter wouldn't reset the indentation correctly, resulting in an underflow for the indent count. Changelog: fixed
1 parent 63086b2 commit b3cc7cf

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

compiler/src/format.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -2584,11 +2584,19 @@ impl Generator {
25842584
Node::IndentNext(nodes) if wrap.is_enabled() => {
25852585
self.pending_indents += 1;
25862586

2587+
let before = self.pending_indents;
2588+
25872589
for n in nodes {
25882590
self.node(n, wrap);
25892591
}
25902592

2591-
self.indent -= 2;
2593+
// If we didn't encounter a new line, reset the state. If we do,
2594+
// we have to dedent the lines that follow.
2595+
if self.pending_indents == before {
2596+
self.pending_indents -= 1;
2597+
} else {
2598+
self.indent -= 2;
2599+
}
25922600
}
25932601
Node::IndentNext(nodes) => {
25942602
for n in nodes {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn foo {
2+
aaa.aaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.cccc('aaaaaaaa').cccc('aaa').cccc(aaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb)
3+
100
4+
}
5+
6+
fn bar {
7+
aaa.aaaaaaaaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.cccc('aaaaaaaa').cccc('aaa').cccc(aaaa)
8+
100
9+
}
10+
11+
fn baz {
12+
# line
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
fn foo {
2+
aaa
3+
.aaaaaaaaaaaaaaaaa
4+
.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
5+
.cccc('aaaaaaaa')
6+
.cccc('aaa')
7+
.cccc(
8+
aaaa,
9+
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb,
10+
)
11+
100
12+
}
13+
14+
fn bar {
15+
aaa
16+
.aaaaaaaaaaaaaaaaa
17+
.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
18+
.cccc('aaaaaaaa')
19+
.cccc('aaa')
20+
.cccc(aaaa)
21+
100
22+
}
23+
24+
fn baz {
25+
# line
26+
}

0 commit comments

Comments
 (0)