From a2947f689780d526c760bd2b8ea7951c5b125876 Mon Sep 17 00:00:00 2001 From: Jan Scheer Date: Sat, 29 May 2021 00:46:25 +0200 Subject: [PATCH] fix clippy warning --- src/uu/basename/src/basename.rs | 2 +- src/uu/cp/src/cp.rs | 6 +++--- src/uu/csplit/src/csplit.rs | 9 +++++---- src/uu/ls/src/ls.rs | 3 +-- src/uu/od/src/parse_inputs.rs | 6 +++--- src/uu/printenv/src/printenv.rs | 9 +++++---- src/uu/ptx/src/ptx.rs | 11 +++++++---- src/uu/sort/src/sort.rs | 6 +++--- src/uucore/src/lib/lib.rs | 13 +++++++------ src/uucore/src/lib/mods/backup_control.rs | 2 +- 10 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/uu/basename/src/basename.rs b/src/uu/basename/src/basename.rs index c20561b30..e6476e436 100644 --- a/src/uu/basename/src/basename.rs +++ b/src/uu/basename/src/basename.rs @@ -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(); diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index fab1dfec1..68ad3ed84 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -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(()), diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index f67f4958f..43f95fff5 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -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 + '_ { - 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()) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index d467d431a..17e0a16a8 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -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 { let file_type = path.file_type()?; diff --git a/src/uu/od/src/parse_inputs.rs b/src/uu/od/src/parse_inputs.rs index 533f4f106..288c0870f 100644 --- a/src/uu/od/src/parse_inputs.rs +++ b/src/uu/od/src/parse_inputs.rs @@ -76,7 +76,7 @@ pub fn parse_inputs(matches: &dyn CommandLineOpts) -> Result) -> Result 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::>(), + inputs: inputs.iter().map(|&s| s.to_string()).collect::>(), option_names, } } diff --git a/src/uu/printenv/src/printenv.rs b/src/uu/printenv/src/printenv.rs index 34571ddad..25cb58185 100644 --- a/src/uu/printenv/src/printenv.rs +++ b/src/uu/printenv/src/printenv.rs @@ -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() { diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index d2aa619b4..a17f7c810 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -108,10 +108,13 @@ impl WordFilter { // Ignore empty string regex from cmd-line-args let arg_reg: Option = 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 { diff --git a/src/uu/sort/src/sort.rs b/src/uu/sort/src/sort.rs index 0efce00e6..5fdaf32cf 100644 --- a/src/uu/sort/src/sort.rs +++ b/src/uu/sort/src/sort.rs @@ -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] diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index c17f14516..e7f29e20c 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -146,15 +146,16 @@ pub trait Args: Iterator + 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) } } diff --git a/src/uucore/src/lib/mods/backup_control.rs b/src/uucore/src/lib/mods/backup_control.rs index 6004ae84d..83268d351 100644 --- a/src/uucore/src/lib/mods/backup_control.rs +++ b/src/uucore/src/lib/mods/backup_control.rs @@ -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()) } }