From 57548aa096f31d90b9606f882f5815a93b2570b3 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Tue, 7 Sep 2021 19:49:56 -0500 Subject: [PATCH] fix: resolve idempotency issue in extern body elements --- src/missed_spans.rs | 20 ++++++++++++-------- tests/source/issue_4963.rs | 5 +++++ tests/target/issue_4963.rs | 9 +++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 tests/source/issue_4963.rs create mode 100644 tests/target/issue_4963.rs diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 263d840785a..28edcb784b4 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -51,6 +51,14 @@ impl<'a> FmtVisitor<'a> { } pub(crate) fn format_missing_with_indent(&mut self, end: BytePos) { + self.format_missing_indent(end, true) + } + + pub(crate) fn format_missing_no_indent(&mut self, end: BytePos) { + self.format_missing_indent(end, false) + } + + fn format_missing_indent(&mut self, end: BytePos, should_indent: bool) { let config = self.config; self.format_missing_inner(end, |this, last_snippet, snippet| { this.push_str(last_snippet.trim_end()); @@ -58,14 +66,10 @@ impl<'a> FmtVisitor<'a> { // No new lines in the snippet. this.push_str("\n"); } - let indent = this.block_indent.to_string(config); - this.push_str(&indent); - }) - } - - pub(crate) fn format_missing_no_indent(&mut self, end: BytePos) { - self.format_missing_inner(end, |this, last_snippet, _| { - this.push_str(last_snippet.trim_end()); + if should_indent { + let indent = this.block_indent.to_string(config); + this.push_str(&indent); + } }) } diff --git a/tests/source/issue_4963.rs b/tests/source/issue_4963.rs new file mode 100644 index 00000000000..32e1f6cd41b --- /dev/null +++ b/tests/source/issue_4963.rs @@ -0,0 +1,5 @@ +mod test { + extern "C" {fn test();} +} + +extern "C" {fn test();} \ No newline at end of file diff --git a/tests/target/issue_4963.rs b/tests/target/issue_4963.rs new file mode 100644 index 00000000000..0c3c13579c1 --- /dev/null +++ b/tests/target/issue_4963.rs @@ -0,0 +1,9 @@ +mod test { + extern "C" { + fn test(); + } +} + +extern "C" { + fn test(); +}