fix clippy warning

This commit is contained in:
Jan Scheer 2021-05-29 00:46:25 +02:00
parent bb268d1500
commit a2947f6897
10 changed files with 36 additions and 31 deletions

View file

@ -136,7 +136,7 @@ fn basename(fullname: &str, suffix: &str) -> String {
}
}
#[allow(clippy::manual_strip)] // can be replaced with strip_suffix once the minimum rust version is 1.45
// can be replaced with strip_suffix once the minimum rust version is 1.45
fn strip_suffix(name: &str, suffix: &str) -> String {
if name == suffix {
return name.to_owned();

View file

@ -669,8 +669,8 @@ impl Options {
}
},
backup: backup_mode,
backup_suffix: backup_suffix,
overwrite: overwrite,
backup_suffix,
overwrite,
no_target_dir,
preserve_attributes,
recursive,
@ -1089,7 +1089,7 @@ fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResu
}
#[cfg(not(windows))]
#[allow(clippy::unnecessary_wraps)] // needed for windows version
#[allow(clippy::unnecessary_unwrap)] // needed for windows version
fn symlink_file(source: &Path, dest: &Path, context: &str) -> CopyResult<()> {
match std::os::unix::fs::symlink(source, dest).context(context) {
Ok(_) => Ok(()),

View file

@ -483,10 +483,11 @@ where
/// Shrink the buffer so that its length is equal to the set size, returning an iterator for
/// the elements that were too much.
fn shrink_buffer_to_size(&mut self) -> impl Iterator<Item = String> + '_ {
let mut shrink_offset = 0;
if self.buffer.len() > self.size {
shrink_offset = self.buffer.len() - self.size;
}
let shrink_offset = if self.buffer.len() > self.size {
self.buffer.len() - self.size
} else {
0
};
self.buffer
.drain(..shrink_offset)
.map(|(_, line)| line.unwrap())

View file

@ -1614,7 +1614,7 @@ fn display_date(metadata: &Metadata, config: &Config) -> String {
Some(time) => {
//Date is recent if from past 6 months
//According to GNU a Gregorian year has 365.2425 * 24 * 60 * 60 == 31556952 seconds on the average.
let recent = time + chrono::Duration::seconds(31556952 / 2) > chrono::Local::now();
let recent = time + chrono::Duration::seconds(31_556_952 / 2) > chrono::Local::now();
match config.time_style {
TimeStyle::FullIso => time.format("%Y-%m-%d %H:%M:%S.%f %z"),
@ -1696,7 +1696,6 @@ fn file_is_executable(md: &Metadata) -> bool {
md.mode() & ((S_IXUSR | S_IXGRP | S_IXOTH) as u32) != 0
}
#[allow(clippy::clippy::collapsible_else_if)]
fn classify_file(path: &PathData) -> Option<char> {
let file_type = path.file_type()?;

View file

@ -76,7 +76,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result<CommandLineInputs,
input_strings.push("-");
}
Ok(CommandLineInputs::FileNames(
input_strings.iter().map(|s| s.to_string()).collect(),
input_strings.iter().map(|&s| s.to_string()).collect(),
))
}
@ -92,7 +92,7 @@ pub fn parse_inputs_traditional(input_strings: Vec<&str>) -> Result<CommandLineI
Ok(match offset0 {
Ok(n) => CommandLineInputs::FileAndOffset(("-".to_string(), n, None)),
_ => CommandLineInputs::FileNames(
input_strings.iter().map(|s| s.to_string()).collect(),
input_strings.iter().map(|&s| s.to_string()).collect(),
),
})
}
@ -179,7 +179,7 @@ mod tests {
impl<'a> MockOptions<'a> {
fn new(inputs: Vec<&'a str>, option_names: Vec<&'a str>) -> MockOptions<'a> {
MockOptions {
inputs: inputs.iter().map(|s| s.to_string()).collect::<Vec<_>>(),
inputs: inputs.iter().map(|&s| s.to_string()).collect::<Vec<_>>(),
option_names,
}
}

View file

@ -50,10 +50,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.map(|v| v.map(ToString::to_string).collect())
.unwrap_or_default();
let mut separator = "\n";
if matches.is_present(OPT_NULL) {
separator = "\x00";
}
let separator = if matches.is_present(OPT_NULL) {
"\x00"
} else {
"\n"
};
if variables.is_empty() {
for (env_var, value) in env::vars() {

View file

@ -108,10 +108,13 @@ impl WordFilter {
// Ignore empty string regex from cmd-line-args
let arg_reg: Option<String> = if matches.is_present(options::WORD_REGEXP) {
match matches.value_of(options::WORD_REGEXP) {
Some(v) => match v.is_empty() {
true => None,
false => Some(v.to_string()),
},
Some(v) => {
if v.is_empty() {
None
} else {
Some(v.to_string())
}
}
None => None,
}
} else {

View file

@ -296,10 +296,10 @@ impl<'a> Line<'a> {
fn print(&self, writer: &mut impl Write, settings: &GlobalSettings) {
if settings.zero_terminated && !settings.debug {
crash_if_err!(1, writer.write_all(self.line.as_bytes()));
crash_if_err!(1, writer.write_all("\0".as_bytes()));
crash_if_err!(1, writer.write_all(b"\0"));
} else if !settings.debug {
crash_if_err!(1, writer.write_all(self.line.as_bytes()));
crash_if_err!(1, writer.write_all("\n".as_bytes()));
crash_if_err!(1, writer.write_all(b"\n"));
} else {
crash_if_err!(1, self.print_debug(settings, writer));
}
@ -1437,7 +1437,7 @@ mod tests {
fn test_get_hash() {
let a = "Ted".to_string();
assert_eq!(2646829031758483623, get_hash(&a));
assert_eq!(2_646_829_031_758_483_623, get_hash(&a));
}
#[test]

View file

@ -146,15 +146,16 @@ pub trait Args: Iterator<Item = OsString> + Sized {
InvalidEncodingHandling::Ignore => s.is_ok(),
_ => true,
})
.map(|s| match s.is_ok() {
true => s.unwrap(),
false => s.unwrap_err(),
.map(|s| match s {
Ok(v) => v,
Err(e) => e,
})
.collect();
match full_conversion {
true => ConversionResult::Complete(result_vector),
false => ConversionResult::Lossy(result_vector),
if full_conversion {
ConversionResult::Complete(result_vector)
} else {
ConversionResult::Lossy(result_vector)
}
}

View file

@ -33,7 +33,7 @@ pub fn determine_backup_suffix(supplied_suffix: Option<&str>) -> String {
if let Some(suffix) = supplied_suffix {
String::from(suffix)
} else {
env::var("SIMPLE_BACKUP_SUFFIX").unwrap_or("~".to_owned())
env::var("SIMPLE_BACKUP_SUFFIX").unwrap_or_else(|_| "~".to_owned())
}
}