mirror of
https://github.com/uutils/diffutils.git
synced 2026-06-10 15:48:59 -07:00
Fix some clippy warnings
This commit is contained in:
@@ -33,7 +33,7 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
let exe = match opts.next() {
|
||||
Some(from) => from,
|
||||
None => {
|
||||
return Err(format!("Usage: <exe> <from> <to>"));
|
||||
return Err("Usage: <exe> <from> <to>".to_string());
|
||||
}
|
||||
};
|
||||
let mut from = None;
|
||||
@@ -55,8 +55,8 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
continue;
|
||||
}
|
||||
let p = osstr_bytes(¶m);
|
||||
if p.get(0) == Some(&b'-') && p.get(1) != Some(&b'-') {
|
||||
let mut bit = p[1..].into_iter().copied().peekable();
|
||||
if p.first() == Some(&b'-') && p.get(1) != Some(&b'-') {
|
||||
let mut bit = p[1..].iter().copied().peekable();
|
||||
// Can't use a for loop because `diff -30u` is supposed to make a diff
|
||||
// with 30 lines of context.
|
||||
while let Some(b) = bit.next() {
|
||||
@@ -64,31 +64,31 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
b'0'..=b'9' => {
|
||||
context_count = (b - b'0') as usize;
|
||||
while let Some(b'0'..=b'9') = bit.peek() {
|
||||
context_count = context_count * 10;
|
||||
context_count *= 10;
|
||||
context_count += (bit.next().unwrap() - b'0') as usize;
|
||||
}
|
||||
}
|
||||
b'c' => {
|
||||
if format.is_some() && format != Some(Format::Context) {
|
||||
return Err(format!("Conflicting output style options"));
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Context);
|
||||
}
|
||||
b'e' => {
|
||||
if format.is_some() && format != Some(Format::Ed) {
|
||||
return Err(format!("Conflicting output style options"));
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Ed);
|
||||
}
|
||||
b'u' => {
|
||||
if format.is_some() && format != Some(Format::Unified) {
|
||||
return Err(format!("Conflicting output style options"));
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Unified);
|
||||
}
|
||||
b'U' => {
|
||||
if format.is_some() && format != Some(Format::Unified) {
|
||||
return Err(format!("Conflicting output style options"));
|
||||
return Err("Conflicting output style options".to_string());
|
||||
}
|
||||
format = Some(Format::Unified);
|
||||
let context_count_maybe = if bit.peek().is_some() {
|
||||
@@ -102,7 +102,7 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
|
||||
context_count = context_count_maybe;
|
||||
break;
|
||||
} else {
|
||||
return Err(format!("Invalid context count"));
|
||||
return Err("Invalid context count".to_string());
|
||||
}
|
||||
}
|
||||
_ => return Err(format!("Unknown option: {}", String::from_utf8_lossy(&[b]))),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::collections::VecDeque;
|
||||
use std::io::Write;
|
||||
use std::mem;
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum DiffLine {
|
||||
@@ -106,7 +106,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
|
||||
if let Some(DiffLine::Add(content)) =
|
||||
mismatch.expected.get_mut(expected_lines_change_idx)
|
||||
{
|
||||
let content = mem::replace(content, Vec::new());
|
||||
let content = std::mem::take(content);
|
||||
mismatch.expected[expected_lines_change_idx] = DiffLine::Change(content);
|
||||
expected_lines_change_idx = expected_lines_change_idx.wrapping_sub(1); // if 0, becomes !0
|
||||
mismatch.actual.push(DiffLine::Change(str.to_vec()));
|
||||
@@ -192,7 +192,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
|
||||
results.push(mismatch);
|
||||
results.remove(0);
|
||||
|
||||
if results.len() == 0 && expected_lines_count != actual_lines_count {
|
||||
if results.is_empty() && expected_lines_count != actual_lines_count {
|
||||
let mut mismatch = Mismatch::new(expected_lines.len(), actual_lines.len());
|
||||
// empty diff and only expected lines has a missing line at end
|
||||
if expected_lines_count != expected_lines.len() {
|
||||
@@ -230,19 +230,15 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
|
||||
|
||||
// hunks with pure context lines get truncated to empty
|
||||
for mismatch in &mut results {
|
||||
if mismatch
|
||||
if !mismatch
|
||||
.expected
|
||||
.iter()
|
||||
.find(|x| !matches!(x, DiffLine::Context(_)))
|
||||
.is_none()
|
||||
.iter().any(|x| !matches!(&x, DiffLine::Context(_)))
|
||||
{
|
||||
mismatch.expected_all_context = true;
|
||||
}
|
||||
if mismatch
|
||||
if !mismatch
|
||||
.actual
|
||||
.iter()
|
||||
.find(|x| !matches!(x, DiffLine::Context(_)))
|
||||
.is_none()
|
||||
.iter().any(|x| !matches!(&x, DiffLine::Context(_)))
|
||||
{
|
||||
mismatch.actual_all_context = true;
|
||||
}
|
||||
@@ -261,7 +257,7 @@ pub fn diff(
|
||||
let mut output =
|
||||
format!("*** {}\t\n--- {}\t\n", expected_filename, actual_filename).into_bytes();
|
||||
let diff_results = make_diff(expected, actual, context_size);
|
||||
if diff_results.len() == 0 {
|
||||
if diff_results.is_empty() {
|
||||
return Vec::new();
|
||||
};
|
||||
for result in diff_results {
|
||||
|
||||
@@ -48,8 +48,8 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Result<Vec<Mismatch>, DiffError>
|
||||
|
||||
debug_assert_eq!(b"".split(|&c| c == b'\n').count(), 1);
|
||||
// ^ means that underflow here is impossible
|
||||
let expected_lines_count = expected_lines.len() - 1;
|
||||
let actual_lines_count = actual_lines.len() - 1;
|
||||
let _expected_lines_count = expected_lines.len() - 1;
|
||||
let _actual_lines_count = actual_lines.len() - 1;
|
||||
|
||||
if expected_lines.last() == Some(&&b""[..]) {
|
||||
expected_lines.pop();
|
||||
@@ -66,7 +66,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Result<Vec<Mismatch>, DiffError>
|
||||
for result in diff::slice(&expected_lines, &actual_lines) {
|
||||
match result {
|
||||
diff::Result::Left(str) => {
|
||||
if mismatch.actual.len() != 0 {
|
||||
if !mismatch.actual.is_empty() {
|
||||
results.push(mismatch);
|
||||
mismatch = Mismatch::new(line_number_expected, line_number_actual);
|
||||
}
|
||||
@@ -77,10 +77,10 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Result<Vec<Mismatch>, DiffError>
|
||||
mismatch.actual.push(str.to_vec());
|
||||
line_number_actual += 1;
|
||||
}
|
||||
diff::Result::Both(str, _) => {
|
||||
diff::Result::Both(_str, _) => {
|
||||
line_number_expected += 1;
|
||||
line_number_actual += 1;
|
||||
if mismatch.actual.len() != 0 || mismatch.expected.len() != 0 {
|
||||
if !mismatch.actual.is_empty() || !mismatch.expected.is_empty() {
|
||||
results.push(mismatch);
|
||||
mismatch = Mismatch::new(line_number_expected, line_number_actual);
|
||||
} else {
|
||||
@@ -91,7 +91,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Result<Vec<Mismatch>, DiffError>
|
||||
}
|
||||
}
|
||||
|
||||
if mismatch.actual.len() != 0 || mismatch.expected.len() != 0 {
|
||||
if !mismatch.actual.is_empty() || !mismatch.expected.is_empty() {
|
||||
results.push(mismatch);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Result<Vec<u8>, DiffError> {
|
||||
let mut lines_offset = 0;
|
||||
for result in diff_results {
|
||||
let line_number_expected: isize = result.line_number_expected as isize + lines_offset;
|
||||
let line_number_actual: isize = result.line_number_actual as isize + lines_offset;
|
||||
let _line_number_actual: isize = result.line_number_actual as isize + lines_offset;
|
||||
let expected_count: isize = result.expected.len() as isize;
|
||||
let actual_count: isize = result.actual.len() as isize;
|
||||
match (expected_count, actual_count) {
|
||||
@@ -137,13 +137,13 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Result<Vec<u8>, DiffError> {
|
||||
writeln!(&mut output, "..\n.\ns/.//\na").unwrap();
|
||||
} else {
|
||||
output.write_all(actual).unwrap();
|
||||
writeln!(&mut output, "").unwrap();
|
||||
writeln!(&mut output).unwrap();
|
||||
}
|
||||
}
|
||||
writeln!(&mut output, ".").unwrap();
|
||||
}
|
||||
}
|
||||
return Ok(output)
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
pub fn diff_w(expected: &[u8], actual: &[u8], filename: &str) -> Result<Vec<u8>, DiffError> {
|
||||
|
||||
@@ -49,7 +49,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Vec<Mismatch> {
|
||||
for result in diff::slice(&expected_lines, &actual_lines) {
|
||||
match result {
|
||||
diff::Result::Left(str) => {
|
||||
if mismatch.actual.len() != 0 && !mismatch.actual_missing_nl {
|
||||
if !mismatch.actual.is_empty() && !mismatch.actual_missing_nl {
|
||||
results.push(mismatch);
|
||||
mismatch = Mismatch::new(line_number_expected, line_number_actual);
|
||||
}
|
||||
@@ -81,7 +81,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Vec<Mismatch> {
|
||||
(true, true) | (false, false) => {
|
||||
line_number_expected += 1;
|
||||
line_number_actual += 1;
|
||||
if mismatch.actual.len() != 0 || mismatch.expected.len() != 0 {
|
||||
if !mismatch.actual.is_empty() || !mismatch.expected.is_empty() {
|
||||
results.push(mismatch);
|
||||
mismatch = Mismatch::new(line_number_expected, line_number_actual);
|
||||
} else {
|
||||
@@ -94,7 +94,7 @@ fn make_diff(expected: &[u8], actual: &[u8]) -> Vec<Mismatch> {
|
||||
}
|
||||
}
|
||||
|
||||
if mismatch.actual.len() != 0 || mismatch.expected.len() != 0 {
|
||||
if !mismatch.actual.is_empty() || !mismatch.expected.is_empty() {
|
||||
results.push(mismatch);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Vec<u8> {
|
||||
for expected in &result.expected {
|
||||
write!(&mut output, "< ").unwrap();
|
||||
output.write_all(expected).unwrap();
|
||||
writeln!(&mut output, "").unwrap();
|
||||
writeln!(&mut output).unwrap();
|
||||
}
|
||||
if result.expected_missing_nl {
|
||||
writeln!(&mut output, r"\ No newline at end of file").unwrap();
|
||||
@@ -151,7 +151,7 @@ pub fn diff(expected: &[u8], actual: &[u8]) -> Vec<u8> {
|
||||
for actual in &result.actual {
|
||||
write!(&mut output, "> ").unwrap();
|
||||
output.write_all(actual).unwrap();
|
||||
writeln!(&mut output, "").unwrap();
|
||||
writeln!(&mut output).unwrap();
|
||||
}
|
||||
if result.actual_missing_nl {
|
||||
writeln!(&mut output, r"\ No newline at end of file").unwrap();
|
||||
|
||||
@@ -180,7 +180,7 @@ fn make_diff(expected: &[u8], actual: &[u8], context_size: usize) -> Vec<Mismatc
|
||||
results.push(mismatch);
|
||||
results.remove(0);
|
||||
|
||||
if results.len() == 0 && expected_lines_count != actual_lines_count {
|
||||
if results.is_empty() && expected_lines_count != actual_lines_count {
|
||||
let mut mismatch = Mismatch::new(expected_lines.len() as u32, actual_lines.len() as u32);
|
||||
// empty diff and only expected lines has a missing line at end
|
||||
if expected_lines_count != expected_lines.len() as u32 {
|
||||
@@ -229,7 +229,7 @@ pub fn diff(
|
||||
let mut output =
|
||||
format!("--- {}\t\n+++ {}\t\n", expected_filename, actual_filename).into_bytes();
|
||||
let diff_results = make_diff(expected, actual, context_size);
|
||||
if diff_results.len() == 0 {
|
||||
if diff_results.is_empty() {
|
||||
return Vec::new();
|
||||
};
|
||||
for result in diff_results {
|
||||
|
||||
Reference in New Issue
Block a user