diff --git a/lib/src/conflicts.rs b/lib/src/conflicts.rs index 5bcd56700..5cb08cb8f 100644 --- a/lib/src/conflicts.rs +++ b/lib/src/conflicts.rs @@ -196,17 +196,18 @@ pub fn materialize_merge_result( output.write_all(CONFLICT_START_LINE)?; let mut add_index = 0; for left in &removes { - if add_index == adds.len() { + let right1 = if let Some(right1) = adds.get(add_index) { + right1 + } else { // If we have no more positive terms, emit the remaining negative // terms as snapshots. output.write_all(CONFLICT_MINUS_LINE)?; output.write_all(left)?; continue; - } - let diff1 = - Diff::for_tokenizer(&[left, &adds[add_index]], &find_line_ranges) - .hunks() - .collect_vec(); + }; + let diff1 = Diff::for_tokenizer(&[left, right1], &find_line_ranges) + .hunks() + .collect_vec(); // Check if the diff against the next positive term is better. Since // we want to preserve the order of the terms, we don't match against // any later positive terms. @@ -219,7 +220,7 @@ pub fn materialize_merge_result( // the current positive term as a snapshot and the next // positive term as a diff. output.write_all(CONFLICT_PLUS_LINE)?; - output.write_all(&adds[add_index])?; + output.write_all(right1)?; output.write_all(CONFLICT_DIFF_LINE)?; write_diff_hunks(&diff2, output)?; add_index += 2;