Skip to content

Commit 95050ac

Browse files
committed
address warnings
1 parent c509a48 commit 95050ac

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

text/diff_util/file_diff.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl<'a> FileDiff<'a> {
174174
if let OutputFormat::Context(context) = self.format_options.output_format {
175175
self.print_context(context);
176176
} else if let OutputFormat::Unified(unified) = self.format_options.output_format {
177-
self.print_unified(unified);
177+
let _ = self.print_unified(unified);
178178
} else {
179179
let hunks_count = self.hunks.hunks().len();
180180

@@ -443,20 +443,20 @@ impl<'a> FileDiff<'a> {
443443
}
444444
}
445445

446-
fn print_line(&self, lines: &mut String, start: usize, end: usize, prefix: &str) -> usize {
446+
fn print_line(&self, lines: &mut String, start: usize, end: usize, prefix: &str) -> Result<usize, std::fmt::Error> {
447447
let mut j = 0;
448448
for i in start..end {
449449
if prefix == "+" {
450-
writeln!(lines, "{prefix}{}", self.file2.line(i));
450+
writeln!(lines, "{prefix}{}", self.file2.line(i))?;
451451
} else {
452-
writeln!(lines, "{prefix}{}", self.file1.line(i));
452+
writeln!(lines, "{prefix}{}", self.file1.line(i))?;
453453
}
454454
j += 1;
455455
}
456-
j
456+
Ok(j)
457457
}
458458

459-
fn print_unified(&mut self, unified: usize) {
459+
fn print_unified(&mut self, unified: usize) -> Result<(), std::fmt::Error> {
460460
println!(
461461
"--- {}",
462462
Self::get_header(self.file1, &self.format_options.label1)
@@ -476,7 +476,7 @@ impl<'a> FileDiff<'a> {
476476
// keep track of the length of the current hunk
477477
let mut hunk1_len = 0;
478478
let mut hunk2_len = 0;
479-
let mut offset = 0;
479+
let mut offset: usize;
480480
let mut lines = String::new();
481481

482482
for hunk in self.hunks.hunks() {
@@ -494,8 +494,7 @@ impl<'a> FileDiff<'a> {
494494
// do we have enough context between hunks?
495495
if (curr_pos1 != 0) && (hunk.ln1_start() - curr_pos1 > unified * 2) {
496496
// print the context after the previous hunk
497-
offset = self.print_line(&mut lines, curr_pos1, curr_pos1 + unified, " ");
498-
// println!("Offset after final context: {}", offset);
497+
offset = self.print_line(&mut lines, curr_pos1, curr_pos1 + unified, " ")?;
499498
hunk1_len += offset;
500499
hunk2_len += offset;
501500
// print a new section start
@@ -521,19 +520,16 @@ impl<'a> FileDiff<'a> {
521520
}
522521

523522
// print context before current hunk
524-
offset = self.print_line(&mut lines, curr_pos1, hunk.ln1_start(), " ");
525-
// println!("Offset after initial context: {}", offset);
523+
offset = self.print_line(&mut lines, curr_pos1, hunk.ln1_start(), " ")?;
526524
curr_pos1 += offset;
527525
hunk1_len += offset;
528526
hunk2_len += offset;
529527
// print delete hunk
530-
offset = self.print_line(&mut lines, hunk.ln1_start(), hunk.ln1_end(), "-");
531-
// println!("Offset after delete context: {}", offset);
528+
offset = self.print_line(&mut lines, hunk.ln1_start(), hunk.ln1_end(), "-")?;
532529
curr_pos1 += offset;
533530
hunk1_len += offset;
534531
// print insert hunk
535-
offset = self.print_line(&mut lines, hunk.ln2_start(), hunk.ln2_end(), "+");
536-
// println!("Offset after insert context: {}", offset);
532+
offset = self.print_line(&mut lines, hunk.ln2_start(), hunk.ln2_end(), "+")?;
537533
hunk2_len += offset;
538534
}
539535

@@ -558,6 +554,7 @@ impl<'a> FileDiff<'a> {
558554
if !self.file2.ends_with_newline() {
559555
println!("{}", NO_NEW_LINE_AT_END_OF_FILE);
560556
}
557+
Ok(())
561558
}
562559

563560
pub fn get_header(file: &FileData, label: &Option<String>) -> String {

0 commit comments

Comments
 (0)