Skip to content

Commit d891e10

Browse files
committed
run clippy pedantic
$ cargo +nightly clippy --allow-dirty --fix -- -W clippy::pedantic
1 parent fdc35f6 commit d891e10

File tree

6 files changed

+133
-184
lines changed

6 files changed

+133
-184
lines changed

src/context_diff.rs

+34-43
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
253253
results
254254
}
255255

256+
#[must_use]
256257
pub fn diff(
257258
expected: &[u8],
258259
expected_filename: &str,
259260
actual: &[u8],
260261
actual_filename: &str,
261262
context_size: usize,
262263
) -> Vec<u8> {
263-
let mut output =
264-
format!("*** {}\t\n--- {}\t\n", expected_filename, actual_filename).into_bytes();
264+
let mut output = format!("*** {expected_filename}\t\n--- {actual_filename}\t\n").into_bytes();
265265
let diff_results = make_diff(expected, actual, context_size);
266266
if diff_results.is_empty() {
267267
return Vec::new();
@@ -284,17 +284,16 @@ pub fn diff(
284284
let exp_start = if end_line_number_expected == line_number_expected {
285285
String::new()
286286
} else {
287-
format!("{},", line_number_expected)
287+
format!("{line_number_expected},")
288288
};
289289
let act_start = if end_line_number_actual == line_number_actual {
290290
String::new()
291291
} else {
292-
format!("{},", line_number_actual)
292+
format!("{line_number_actual},")
293293
};
294294
writeln!(
295295
output,
296-
"***************\n*** {}{} ****",
297-
exp_start, end_line_number_expected
296+
"***************\n*** {exp_start}{end_line_number_expected} ****"
298297
)
299298
.expect("write to Vec is infallible");
300299
if !result.expected_all_context {
@@ -322,7 +321,7 @@ pub fn diff(
322321
.expect("write to Vec is infallible");
323322
}
324323
}
325-
writeln!(output, "--- {}{} ----", act_start, end_line_number_actual)
324+
writeln!(output, "--- {act_start}{end_line_number_actual} ----")
326325
.expect("write to Vec is infallible");
327326
if !result.actual_all_context {
328327
for line in result.actual {
@@ -406,29 +405,27 @@ mod tests {
406405
// This test diff is intentionally reversed.
407406
// We want it to turn the alef into bet.
408407
let diff =
409-
diff(&alef, "a/alef", &bet, &format!("{}/alef", target), 2);
410-
File::create(&format!("{}/ab.diff", target))
408+
diff(&alef, "a/alef", &bet, &format!("{target}/alef"), 2);
409+
File::create(&format!("{target}/ab.diff"))
411410
.unwrap()
412411
.write_all(&diff)
413412
.unwrap();
414-
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
413+
let mut fa = File::create(&format!("{target}/alef")).unwrap();
415414
fa.write_all(&alef[..]).unwrap();
416-
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
415+
let mut fb = File::create(&format!("{target}/bet")).unwrap();
417416
fb.write_all(&bet[..]).unwrap();
418417
let _ = fa;
419418
let _ = fb;
420419
let output = Command::new("patch")
421420
.arg("-p0")
422421
.arg("--context")
423-
.stdin(File::open(&format!("{}/ab.diff", target)).unwrap())
422+
.stdin(File::open(&format!("{target}/ab.diff")).unwrap())
424423
.output()
425424
.unwrap();
426-
if !output.status.success() {
427-
panic!("{:?}", output);
428-
}
425+
assert!(output.status.success(), "{:?}", output);
429426
//println!("{}", String::from_utf8_lossy(&output.stdout));
430427
//println!("{}", String::from_utf8_lossy(&output.stderr));
431-
let alef = fs::read(&format!("{}/alef", target)).unwrap();
428+
let alef = fs::read(&format!("{target}/alef")).unwrap();
432429
assert_eq!(alef, bet);
433430
}
434431
}
@@ -481,29 +478,27 @@ mod tests {
481478
// This test diff is intentionally reversed.
482479
// We want it to turn the alef into bet.
483480
let diff =
484-
diff(&alef, "a/alef_", &bet, &format!("{}/alef_", target), 2);
485-
File::create(&format!("{}/ab_.diff", target))
481+
diff(&alef, "a/alef_", &bet, &format!("{target}/alef_"), 2);
482+
File::create(&format!("{target}/ab_.diff"))
486483
.unwrap()
487484
.write_all(&diff)
488485
.unwrap();
489-
let mut fa = File::create(&format!("{}/alef_", target)).unwrap();
486+
let mut fa = File::create(&format!("{target}/alef_")).unwrap();
490487
fa.write_all(&alef[..]).unwrap();
491-
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
488+
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
492489
fb.write_all(&bet[..]).unwrap();
493490
let _ = fa;
494491
let _ = fb;
495492
let output = Command::new("patch")
496493
.arg("-p0")
497494
.arg("--context")
498-
.stdin(File::open(&format!("{}/ab_.diff", target)).unwrap())
495+
.stdin(File::open(&format!("{target}/ab_.diff")).unwrap())
499496
.output()
500497
.unwrap();
501-
if !output.status.success() {
502-
panic!("{:?}", output);
503-
}
498+
assert!(output.status.success(), "{:?}", output);
504499
//println!("{}", String::from_utf8_lossy(&output.stdout));
505500
//println!("{}", String::from_utf8_lossy(&output.stderr));
506-
let alef = fs::read(&format!("{}/alef_", target)).unwrap();
501+
let alef = fs::read(&format!("{target}/alef_")).unwrap();
507502
assert_eq!(alef, bet);
508503
}
509504
}
@@ -559,29 +554,27 @@ mod tests {
559554
// This test diff is intentionally reversed.
560555
// We want it to turn the alef into bet.
561556
let diff =
562-
diff(&alef, "a/alefx", &bet, &format!("{}/alefx", target), 2);
563-
File::create(&format!("{}/abx.diff", target))
557+
diff(&alef, "a/alefx", &bet, &format!("{target}/alefx"), 2);
558+
File::create(&format!("{target}/abx.diff"))
564559
.unwrap()
565560
.write_all(&diff)
566561
.unwrap();
567-
let mut fa = File::create(&format!("{}/alefx", target)).unwrap();
562+
let mut fa = File::create(&format!("{target}/alefx")).unwrap();
568563
fa.write_all(&alef[..]).unwrap();
569-
let mut fb = File::create(&format!("{}/betx", target)).unwrap();
564+
let mut fb = File::create(&format!("{target}/betx")).unwrap();
570565
fb.write_all(&bet[..]).unwrap();
571566
let _ = fa;
572567
let _ = fb;
573568
let output = Command::new("patch")
574569
.arg("-p0")
575570
.arg("--context")
576-
.stdin(File::open(&format!("{}/abx.diff", target)).unwrap())
571+
.stdin(File::open(&format!("{target}/abx.diff")).unwrap())
577572
.output()
578573
.unwrap();
579-
if !output.status.success() {
580-
panic!("{:?}", output);
581-
}
574+
assert!(output.status.success(), "{:?}", output);
582575
//println!("{}", String::from_utf8_lossy(&output.stdout));
583576
//println!("{}", String::from_utf8_lossy(&output.stderr));
584-
let alef = fs::read(&format!("{}/alefx", target)).unwrap();
577+
let alef = fs::read(&format!("{target}/alefx")).unwrap();
585578
assert_eq!(alef, bet);
586579
}
587580
}
@@ -640,29 +633,27 @@ mod tests {
640633
// This test diff is intentionally reversed.
641634
// We want it to turn the alef into bet.
642635
let diff =
643-
diff(&alef, "a/alefr", &bet, &format!("{}/alefr", target), 2);
644-
File::create(&format!("{}/abr.diff", target))
636+
diff(&alef, "a/alefr", &bet, &format!("{target}/alefr"), 2);
637+
File::create(&format!("{target}/abr.diff"))
645638
.unwrap()
646639
.write_all(&diff)
647640
.unwrap();
648-
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
641+
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
649642
fa.write_all(&alef[..]).unwrap();
650-
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
643+
let mut fb = File::create(&format!("{target}/betr")).unwrap();
651644
fb.write_all(&bet[..]).unwrap();
652645
let _ = fa;
653646
let _ = fb;
654647
let output = Command::new("patch")
655648
.arg("-p0")
656649
.arg("--context")
657-
.stdin(File::open(&format!("{}/abr.diff", target)).unwrap())
650+
.stdin(File::open(&format!("{target}/abr.diff")).unwrap())
658651
.output()
659652
.unwrap();
660-
if !output.status.success() {
661-
panic!("{:?}", output);
662-
}
653+
assert!(output.status.success(), "{:?}", output);
663654
//println!("{}", String::from_utf8_lossy(&output.stdout));
664655
//println!("{}", String::from_utf8_lossy(&output.stderr));
665-
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
656+
let alef = fs::read(&format!("{target}/alefr")).unwrap();
666657
assert_eq!(alef, bet);
667658
}
668659
}

src/ed_diff.rs

+15-23
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ mod tests {
152152
use super::*;
153153
pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result<Vec<u8>, DiffError> {
154154
let mut output = diff(expected, actual)?;
155-
writeln!(&mut output, "w {}", filename).unwrap();
155+
writeln!(&mut output, "w {filename}").unwrap();
156156
Ok(output)
157157
}
158158

@@ -204,29 +204,26 @@ mod tests {
204204
}
205205
// This test diff is intentionally reversed.
206206
// We want it to turn the alef into bet.
207-
let diff =
208-
diff_w(&alef, &bet, &format!("{}/alef", target)).unwrap();
207+
let diff = diff_w(&alef, &bet, &format!("{target}/alef")).unwrap();
209208
File::create("target/ab.ed")
210209
.unwrap()
211210
.write_all(&diff)
212211
.unwrap();
213-
let mut fa = File::create(&format!("{}/alef", target)).unwrap();
212+
let mut fa = File::create(&format!("{target}/alef")).unwrap();
214213
fa.write_all(&alef[..]).unwrap();
215-
let mut fb = File::create(&format!("{}/bet", target)).unwrap();
214+
let mut fb = File::create(&format!("{target}/bet")).unwrap();
216215
fb.write_all(&bet[..]).unwrap();
217216
let _ = fa;
218217
let _ = fb;
219218
let output = Command::new("ed")
220-
.arg(&format!("{}/alef", target))
219+
.arg(&format!("{target}/alef"))
221220
.stdin(File::open("target/ab.ed").unwrap())
222221
.output()
223222
.unwrap();
224-
if !output.status.success() {
225-
panic!("{:?}", output);
226-
}
223+
assert!(output.status.success(), "{:?}", output);
227224
//println!("{}", String::from_utf8_lossy(&output.stdout));
228225
//println!("{}", String::from_utf8_lossy(&output.stderr));
229-
let alef = fs::read(&format!("{}/alef", target)).unwrap();
226+
let alef = fs::read(&format!("{target}/alef")).unwrap();
230227
assert_eq!(alef, bet);
231228
}
232229
}
@@ -285,7 +282,7 @@ mod tests {
285282
.unwrap();
286283
let mut fa = File::create("target/alef_").unwrap();
287284
fa.write_all(&alef[..]).unwrap();
288-
let mut fb = File::create(&format!("{}/bet_", target)).unwrap();
285+
let mut fb = File::create(&format!("{target}/bet_")).unwrap();
289286
fb.write_all(&bet[..]).unwrap();
290287
let _ = fa;
291288
let _ = fb;
@@ -294,9 +291,7 @@ mod tests {
294291
.stdin(File::open("target/ab_.ed").unwrap())
295292
.output()
296293
.unwrap();
297-
if !output.status.success() {
298-
panic!("{:?}", output);
299-
}
294+
assert!(output.status.success(), "{:?}", output);
300295
//println!("{}", String::from_utf8_lossy(&output.stdout));
301296
//println!("{}", String::from_utf8_lossy(&output.stderr));
302297
let alef = fs::read("target/alef_").unwrap();
@@ -357,29 +352,26 @@ mod tests {
357352
}
358353
// This test diff is intentionally reversed.
359354
// We want it to turn the alef into bet.
360-
let diff =
361-
diff_w(&alef, &bet, &format!("{}/alefr", target)).unwrap();
355+
let diff = diff_w(&alef, &bet, &format!("{target}/alefr")).unwrap();
362356
File::create("target/abr.ed")
363357
.unwrap()
364358
.write_all(&diff)
365359
.unwrap();
366-
let mut fa = File::create(&format!("{}/alefr", target)).unwrap();
360+
let mut fa = File::create(&format!("{target}/alefr")).unwrap();
367361
fa.write_all(&alef[..]).unwrap();
368-
let mut fb = File::create(&format!("{}/betr", target)).unwrap();
362+
let mut fb = File::create(&format!("{target}/betr")).unwrap();
369363
fb.write_all(&bet[..]).unwrap();
370364
let _ = fa;
371365
let _ = fb;
372366
let output = Command::new("ed")
373-
.arg(&format!("{}/alefr", target))
367+
.arg(&format!("{target}/alefr"))
374368
.stdin(File::open("target/abr.ed").unwrap())
375369
.output()
376370
.unwrap();
377-
if !output.status.success() {
378-
panic!("{:?}", output);
379-
}
371+
assert!(output.status.success(), "{:?}", output);
380372
//println!("{}", String::from_utf8_lossy(&output.stdout));
381373
//println!("{}", String::from_utf8_lossy(&output.stderr));
382-
let alef = fs::read(&format!("{}/alefr", target)).unwrap();
374+
let alef = fs::read(&format!("{target}/alefr")).unwrap();
383375
assert_eq!(alef, bet);
384376
}
385377
}

src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE-*
44
// files that was distributed with this source code.
55

6-
use crate::params::*;
6+
use crate::params::{parse_params, Format, Params};
77
use std::env;
88

99
use std::fs;
@@ -27,13 +27,13 @@ fn main() -> Result<(), String> {
2727
let from_content = match fs::read(&from) {
2828
Ok(from_content) => from_content,
2929
Err(e) => {
30-
return Err(format!("Failed to read from-file: {}", e));
30+
return Err(format!("Failed to read from-file: {e}"));
3131
}
3232
};
3333
let to_content = match fs::read(&to) {
3434
Ok(to_content) => to_content,
3535
Err(e) => {
36-
return Err(format!("Failed to read from-file: {}", e));
36+
return Err(format!("Failed to read from-file: {e}"));
3737
}
3838
};
3939
// run diff

0 commit comments

Comments
 (0)