]> git.lizzy.rs Git - rust.git/commitdiff
Take into account a trailing newline in buffer
authorSeiichi Uchida <seuchida@gmail.com>
Tue, 5 Dec 2017 08:15:42 +0000 (17:15 +0900)
committerSeiichi Uchida <seuchida@gmail.com>
Tue, 5 Dec 2017 08:15:42 +0000 (17:15 +0900)
src/missed_spans.rs

index ba99bdd92c045f89cef045009ef1824d8be985c9..94bfc034db6f237324df328c6fcc8734d46f9416 100644 (file)
@@ -87,6 +87,10 @@ fn format_missing_inner<F: Fn(&mut FmtVisitor, &str, &str)>(
     }
 
     fn push_vertical_spaces(&mut self, mut newline_count: usize) {
+        // The buffer already has a trailing newline.
+        if self.buffer.cur_offset() == 0 {
+            newline_count = newline_count.checked_sub(1).unwrap_or(0);
+        }
         let newline_upper_bound = self.config.blank_lines_upper_bound() + 1;
         let newline_lower_bound = self.config.blank_lines_lower_bound() + 1;
         if newline_count > newline_upper_bound {