about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorChris Emerson <github@mail.nosreme.org>2017-10-19 23:14:20 +0100
committerChris Emerson <github@mail.nosreme.org>2017-10-19 23:14:20 +0100
commitf9bcb58eb3f3b6508cd7a24e7728f21fcd8f63b9 (patch)
tree13fe6caa5b90c3beb6d49cd0c8fa0e13379002b1 /src
parent6c1c81bbced8c6d98701ea70845f1626ac703c31 (diff)
Add a couple of special cases which fix the zero-context diff case.
Diffstat (limited to 'src')
-rw-r--r--src/rustfmt_diff.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs
index fa3c6305ed8..d6b021d42d4 100644
--- a/src/rustfmt_diff.rs
+++ b/src/rustfmt_diff.rs
@@ -47,7 +47,7 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
     for result in diff::lines(expected, actual) {
         match result {
             diff::Result::Left(str) => {
-                if lines_since_mismatch >= context_size {
+                if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
                     results.push(mismatch);
                     mismatch = Mismatch::new(line_number - context_queue.len() as u32);
                 }
@@ -60,7 +60,7 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
                 lines_since_mismatch = 0;
             }
             diff::Result::Right(str) => {
-                if lines_since_mismatch >= context_size {
+                if lines_since_mismatch >= context_size && lines_since_mismatch > 0 {
                     results.push(mismatch);
                     mismatch = Mismatch::new(line_number - context_queue.len() as u32);
                 }
@@ -80,7 +80,7 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
 
                 if lines_since_mismatch < context_size {
                     mismatch.lines.push(DiffLine::Context(str.to_owned()));
-                } else {
+                } else if context_size > 0 {
                     context_queue.push_back(str);
                 }