]> git.lizzy.rs Git - rust.git/commitdiff
fix: resolve idempotency issue in extern body elements
authorCaleb Cartwright <caleb.cartwright@outlook.com>
Wed, 8 Sep 2021 00:49:56 +0000 (19:49 -0500)
committerCaleb Cartwright <calebcartwright@users.noreply.github.com>
Wed, 8 Sep 2021 01:22:09 +0000 (20:22 -0500)
src/missed_spans.rs
tests/source/issue_4963.rs [new file with mode: 0644]
tests/target/issue_4963.rs [new file with mode: 0644]

index 263d840785a2953468f42a976058d8490c4a7f53..28edcb784b40ee17030a7660087803dfc347b866 100644 (file)
@@ -51,6 +51,14 @@ pub(crate) fn format_missing(&mut self, end: BytePos) {
     }
 
     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 @@ pub(crate) fn format_missing_with_indent(&mut self, end: BytePos) {
                 // 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 (file)
index 0000000..32e1f6c
--- /dev/null
@@ -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 (file)
index 0000000..0c3c135
--- /dev/null
@@ -0,0 +1,9 @@
+mod test {
+    extern "C" {
+        fn test();
+    }
+}
+
+extern "C" {
+    fn test();
+}