Skip to content

Commit 57548aa

Browse files
fix: resolve idempotency issue in extern body elements
1 parent 3d8cd57 commit 57548aa

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

src/missed_spans.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,25 @@ impl<'a> FmtVisitor<'a> {
5151
}
5252

5353
pub(crate) fn format_missing_with_indent(&mut self, end: BytePos) {
54+
self.format_missing_indent(end, true)
55+
}
56+
57+
pub(crate) fn format_missing_no_indent(&mut self, end: BytePos) {
58+
self.format_missing_indent(end, false)
59+
}
60+
61+
fn format_missing_indent(&mut self, end: BytePos, should_indent: bool) {
5462
let config = self.config;
5563
self.format_missing_inner(end, |this, last_snippet, snippet| {
5664
this.push_str(last_snippet.trim_end());
5765
if last_snippet == snippet && !this.output_at_start() {
5866
// No new lines in the snippet.
5967
this.push_str("\n");
6068
}
61-
let indent = this.block_indent.to_string(config);
62-
this.push_str(&indent);
63-
})
64-
}
65-
66-
pub(crate) fn format_missing_no_indent(&mut self, end: BytePos) {
67-
self.format_missing_inner(end, |this, last_snippet, _| {
68-
this.push_str(last_snippet.trim_end());
69+
if should_indent {
70+
let indent = this.block_indent.to_string(config);
71+
this.push_str(&indent);
72+
}
6973
})
7074
}
7175

tests/source/issue_4963.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mod test {
2+
extern "C" {fn test();}
3+
}
4+
5+
extern "C" {fn test();}

tests/target/issue_4963.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mod test {
2+
extern "C" {
3+
fn test();
4+
}
5+
}
6+
7+
extern "C" {
8+
fn test();
9+
}

0 commit comments

Comments
 (0)