]> git.lizzy.rs Git - rust.git/blobdiff - src/missed_spans.rs
discard trailing blank comments
[rust.git] / src / missed_spans.rs
index 6ff2efa487fe7ce8f7294d6a389bbddf0c1c443c..70d4c66d7fbbd9dbf912a77d71f1ee7c2d7d5a2e 100644 (file)
@@ -43,9 +43,20 @@ fn output_at_start(&self) -> bool {
         self.buffer.is_empty()
     }
 
-    // TODO these format_missing methods are ugly. Refactor and add unit tests
-    // for the central whitespace stripping loop.
     pub fn format_missing(&mut self, end: BytePos) {
+        // HACK(topecongiro)
+        // We use `format_missing()` to extract a missing comment between a macro
+        // (or alike) and a trailing semicolon. Here we just try to avoid calling
+        // `format_missing_inner` in the common case where there is no such comment.
+        // This is a hack, ideally we should fix a possible bug in `format_missing_inner`
+        // or refactor `visit_mac` and `rewrite_macro`, but this should suffice to fix the
+        // issue (#2727).
+        let missing_snippet = self.snippet(mk_sp(self.last_pos, end));
+        if missing_snippet.trim() == ";" {
+            self.push_str(";");
+            self.last_pos = end;
+            return;
+        }
         self.format_missing_inner(end, |this, last_snippet, _| this.push_str(last_snippet))
     }