diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 0a619e097..98691f34b 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -117,7 +117,7 @@ jobs: run: | ## `cargo clippy` lint testing unset fault - CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity" + CLIPPY_FLAGS="-W clippy::default_trait_access -W clippy::manual_string_new -W clippy::cognitive_complexity -W clippy::implicit_clone" fault_type="${{ steps.vars.outputs.FAULT_TYPE }}" fault_prefix=$(echo "$fault_type" | tr '[:lower:]' '[:upper:]') # * convert any warnings to GHA UI annotations; ref: diff --git a/src/uu/base32/src/base_common.rs b/src/uu/base32/src/base_common.rs index 4a30705af..74c3dc808 100644 --- a/src/uu/base32/src/base_common.rs +++ b/src/uu/base32/src/base_common.rs @@ -54,7 +54,7 @@ impl Config { format!("{}: No such file or directory", name.maybe_quote()), )); } - Some(name.to_owned()) + Some(name.clone()) } } None => None, diff --git a/src/uu/cat/src/cat.rs b/src/uu/cat/src/cat.rs index a7a4c5f40..34eb26512 100644 --- a/src/uu/cat/src/cat.rs +++ b/src/uu/cat/src/cat.rs @@ -213,7 +213,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let squeeze_blank = matches.get_flag(options::SQUEEZE_BLANK); let files: Vec = match matches.get_many::(options::FILE) { - Some(v) => v.clone().map(|v| v.to_owned()).collect(), + Some(v) => v.cloned().collect(), None => vec!["-".to_owned()], }; diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index 6e03c2e5c..d33be1a5d 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -62,15 +62,9 @@ impl CsplitOptions { split_name: crash_if_err!( 1, SplitName::new( - matches - .get_one::(options::PREFIX) - .map(|s| s.to_owned()), - matches - .get_one::(options::SUFFIX_FORMAT) - .map(|s| s.to_owned()), - matches - .get_one::(options::DIGITS) - .map(|s| s.to_owned()) + matches.get_one::(options::PREFIX).cloned(), + matches.get_one::(options::SUFFIX_FORMAT).cloned(), + matches.get_one::(options::DIGITS).cloned() ) ), keep_files, diff --git a/src/uu/cut/src/cut.rs b/src/uu/cut/src/cut.rs index 4d3145c05..05e8bc6e4 100644 --- a/src/uu/cut/src/cut.rs +++ b/src/uu/cut/src/cut.rs @@ -400,7 +400,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if s.is_empty() { Some("\0".to_owned()) } else { - Some(s.to_owned()) + Some(s.clone()) } } None => None, @@ -491,7 +491,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let files: Vec = matches .get_many::(options::FILE) .unwrap_or_default() - .map(|s| s.to_owned()) + .cloned() .collect(); match mode_parse { diff --git a/src/uu/dirname/src/dirname.rs b/src/uu/dirname/src/dirname.rs index 9a56e9f5b..51935cb7f 100644 --- a/src/uu/dirname/src/dirname.rs +++ b/src/uu/dirname/src/dirname.rs @@ -30,7 +30,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let dirnames: Vec = matches .get_many::(options::DIR) .unwrap_or_default() - .map(|s| s.to_owned()) + .cloned() .collect(); if dirnames.is_empty() { diff --git a/src/uu/du/src/du.rs b/src/uu/du/src/du.rs index ae88ed13b..9139c31c3 100644 --- a/src/uu/du/src/du.rs +++ b/src/uu/du/src/du.rs @@ -506,7 +506,7 @@ fn build_exclude_patterns(matches: &ArgMatches) -> UResult> { let excludes_iterator = matches .get_many::(options::EXCLUDE) .unwrap_or_default() - .map(|v| v.to_owned()); + .cloned(); let mut exclude_patterns = Vec::new(); for f in excludes_iterator.chain(exclude_from_iterator) { diff --git a/src/uu/fold/src/fold.rs b/src/uu/fold/src/fold.rs index 95b6d9a82..0223248be 100644 --- a/src/uu/fold/src/fold.rs +++ b/src/uu/fold/src/fold.rs @@ -35,7 +35,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let bytes = matches.get_flag(options::BYTES); let spaces = matches.get_flag(options::SPACES); let poss_width = match matches.get_one::(options::WIDTH) { - Some(v) => Some(v.to_owned()), + Some(v) => Some(v.clone()), None => obs_width, }; @@ -50,7 +50,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; let files = match matches.get_many::(options::FILE) { - Some(v) => v.map(|v| v.to_owned()).collect(), + Some(v) => v.cloned().collect(), None => vec!["-".to_owned()], }; diff --git a/src/uu/head/src/head.rs b/src/uu/head/src/head.rs index c533f5a5d..5d0d3bedd 100644 --- a/src/uu/head/src/head.rs +++ b/src/uu/head/src/head.rs @@ -205,7 +205,7 @@ impl HeadOptions { options.mode = Mode::from(matches)?; options.files = match matches.get_many::(options::FILES_NAME) { - Some(v) => v.map(|s| s.to_owned()).collect(), + Some(v) => v.cloned().collect(), None => vec!["-".to_owned()], }; //println!("{:#?}", options); diff --git a/src/uu/install/src/install.rs b/src/uu/install/src/install.rs index 63ba52b1c..43925a7f8 100644 --- a/src/uu/install/src/install.rs +++ b/src/uu/install/src/install.rs @@ -375,9 +375,7 @@ fn behavior(matches: &ArgMatches) -> UResult { }; let backup_mode = backup_control::determine_backup_mode(matches)?; - let target_dir = matches - .get_one::(OPT_TARGET_DIRECTORY) - .map(|d| d.to_owned()); + let target_dir = matches.get_one::(OPT_TARGET_DIRECTORY).cloned(); let preserve_timestamps = matches.get_flag(OPT_PRESERVE_TIMESTAMPS); let compare = matches.get_flag(OPT_COMPARE); @@ -593,7 +591,7 @@ fn standard(mut paths: Vec, b: &Behavior) -> UResult<()> { let source = sources.first().unwrap(); if source.is_dir() { - return Err(InstallError::OmittingDirectory(source.to_path_buf()).into()); + return Err(InstallError::OmittingDirectory(source.clone()).into()); } if target.is_file() || is_new_file_path(&target) { @@ -628,7 +626,7 @@ fn copy_files_into_dir(files: &[PathBuf], target_dir: &Path, b: &Behavior) -> UR } if sourcepath.is_dir() { - let err = InstallError::OmittingDirectory(sourcepath.to_path_buf()); + let err = InstallError::OmittingDirectory(sourcepath.clone()); show!(err); continue; } @@ -701,12 +699,9 @@ fn perform_backup(to: &Path, b: &Behavior) -> UResult> { if let Some(ref backup_path) = backup_path { // TODO!! if let Err(err) = fs::rename(to, backup_path) { - return Err(InstallError::BackupFailed( - to.to_path_buf(), - backup_path.to_path_buf(), - err, - ) - .into()); + return Err( + InstallError::BackupFailed(to.to_path_buf(), backup_path.clone(), err).into(), + ); } } Ok(backup_path) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 327b914dd..88af56bb1 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -577,9 +577,7 @@ fn extract_color(options: &clap::ArgMatches) -> bool { /// /// A QuotingStyle variant representing the quoting style to use. fn extract_quoting_style(options: &clap::ArgMatches, show_control: bool) -> QuotingStyle { - let opt_quoting_style = options - .get_one::(options::QUOTING_STYLE) - .map(|cmd_line_qs| cmd_line_qs.to_owned()); + let opt_quoting_style = options.get_one::(options::QUOTING_STYLE).cloned(); if let Some(style) = opt_quoting_style { match style.as_str() { @@ -788,9 +786,7 @@ impl Config { match parse_size_u64(&raw_bs.to_string_lossy()) { Ok(size) => Some(size), Err(_) => { - show!(LsError::BlockSizeParseError( - cmd_line_bs.unwrap().to_owned() - )); + show!(LsError::BlockSizeParseError(cmd_line_bs.unwrap().clone())); None } } @@ -3056,7 +3052,7 @@ fn display_file_name( target_data.must_dereference, ) { Ok(md) => md, - Err(_) => path.md(out).unwrap().to_owned(), + Err(_) => path.md(out).unwrap().clone(), }; name.push_str(&color_name( @@ -3073,11 +3069,7 @@ fn display_file_name( } } Err(err) => { - show!(LsError::IOErrorContext( - err, - path.p_buf.to_path_buf(), - false - )); + show!(LsError::IOErrorContext(err, path.p_buf.clone(), false)); } } } @@ -3087,7 +3079,7 @@ fn display_file_name( if config.context { if let Some(pad_count) = prefix_context { let security_context = if matches!(config.format, Format::Commas) { - path.security_context.to_owned() + path.security_context.clone() } else { pad_left(&path.security_context, pad_count) }; diff --git a/src/uu/mkfifo/src/mkfifo.rs b/src/uu/mkfifo/src/mkfifo.rs index dc1f876fc..39d112739 100644 --- a/src/uu/mkfifo/src/mkfifo.rs +++ b/src/uu/mkfifo/src/mkfifo.rs @@ -42,7 +42,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { }; let fifos: Vec = match matches.get_many::(options::FIFO) { - Some(v) => v.clone().map(|s| s.to_owned()).collect(), + Some(v) => v.cloned().collect(), None => return Err(USimpleError::new(1, "missing operand")), }; diff --git a/src/uu/mv/src/mv.rs b/src/uu/mv/src/mv.rs index 0ceda8e75..036024f99 100644 --- a/src/uu/mv/src/mv.rs +++ b/src/uu/mv/src/mv.rs @@ -146,7 +146,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let files: Vec = matches .get_many::(ARG_FILES) .unwrap_or_default() - .map(|v| v.to_os_string()) + .cloned() .collect(); let overwrite_mode = determine_overwrite_mode(&matches); diff --git a/src/uu/nl/src/helper.rs b/src/uu/nl/src/helper.rs index ae14a6d59..e617010c1 100644 --- a/src/uu/nl/src/helper.rs +++ b/src/uu/nl/src/helper.rs @@ -19,11 +19,11 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) -> settings.section_delimiter = if delimiter.len() == 1 { format!("{delimiter}:") } else { - delimiter.to_owned() + delimiter.clone() }; } if let Some(val) = opts.get_one::(options::NUMBER_SEPARATOR) { - settings.number_separator = val.to_owned(); + settings.number_separator = val.clone(); } settings.number_format = opts .get_one::(options::NUMBER_FORMAT) diff --git a/src/uu/nl/src/nl.rs b/src/uu/nl/src/nl.rs index 61ca8406f..eaf27f3b6 100644 --- a/src/uu/nl/src/nl.rs +++ b/src/uu/nl/src/nl.rs @@ -195,7 +195,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { } let files: Vec = match matches.get_many::(options::FILE) { - Some(v) => v.clone().map(|v| v.to_owned()).collect(), + Some(v) => v.cloned().collect(), None => vec!["-".to_owned()], }; diff --git a/src/uu/numfmt/src/numfmt.rs b/src/uu/numfmt/src/numfmt.rs index 4afe56555..d1785209d 100644 --- a/src/uu/numfmt/src/numfmt.rs +++ b/src/uu/numfmt/src/numfmt.rs @@ -211,9 +211,7 @@ fn parse_options(args: &ArgMatches) -> Result { _ => unreachable!("Should be restricted by clap"), }; - let suffix = args - .get_one::(options::SUFFIX) - .map(|s| s.to_owned()); + let suffix = args.get_one::(options::SUFFIX).cloned(); let invalid = InvalidModes::from_str(args.get_one::(options::INVALID).unwrap()).unwrap(); diff --git a/src/uu/paste/src/paste.rs b/src/uu/paste/src/paste.rs index 89bba034c..118a66b81 100644 --- a/src/uu/paste/src/paste.rs +++ b/src/uu/paste/src/paste.rs @@ -44,7 +44,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let files = matches .get_many::(options::FILE) .unwrap() - .map(|s| s.to_owned()) + .cloned() .collect(); let line_ending = LineEnding::from_zero_flag(matches.get_flag(options::ZERO_TERMINATED)); diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 1e9532a3a..6dd2b2992 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -720,7 +720,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; let mut input_files: Vec = match &matches.get_many::(options::FILE) { - Some(v) => v.clone().map(|v| v.to_owned()).collect(), + Some(v) => v.clone().cloned().collect(), None => vec!["-".to_string()], }; diff --git a/src/uu/shuf/src/shuf.rs b/src/uu/shuf/src/shuf.rs index 1b21b9532..8c636f1cb 100644 --- a/src/uu/shuf/src/shuf.rs +++ b/src/uu/shuf/src/shuf.rs @@ -75,7 +75,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let headcounts = matches .get_many::(options::HEAD_COUNT) .unwrap_or_default() - .map(|s| s.to_owned()) + .cloned() .collect(); match parse_head_count(headcounts) { Ok(val) => val, diff --git a/src/uu/sort/src/numeric_str_cmp.rs b/src/uu/sort/src/numeric_str_cmp.rs index 661f536a3..c6af856c2 100644 --- a/src/uu/sort/src/numeric_str_cmp.rs +++ b/src/uu/sort/src/numeric_str_cmp.rs @@ -394,8 +394,8 @@ mod tests { let (a_info, a_range) = NumInfo::parse(a, &NumInfoParseSettings::default()); let (b_info, b_range) = NumInfo::parse(b, &NumInfoParseSettings::default()); let ordering = numeric_str_cmp( - (&a[a_range.to_owned()], &a_info), - (&b[b_range.to_owned()], &b_info), + (&a[a_range.clone()], &a_info), + (&b[b_range.clone()], &b_info), ); assert_eq!(ordering, expected); let ordering = numeric_str_cmp((&b[b_range], &b_info), (&a[a_range], &a_info)); diff --git a/src/uu/split/src/split.rs b/src/uu/split/src/split.rs index 4b5cd9207..17a783d72 100644 --- a/src/uu/split/src/split.rs +++ b/src/uu/split/src/split.rs @@ -506,10 +506,10 @@ impl Settings { }; let result = Self { - prefix: matches.get_one::(ARG_PREFIX).unwrap().to_owned(), + prefix: matches.get_one::(ARG_PREFIX).unwrap().clone(), suffix, - input: matches.get_one::(ARG_INPUT).unwrap().to_owned(), - filter: matches.get_one::(OPT_FILTER).map(|s| s.to_owned()), + input: matches.get_one::(ARG_INPUT).unwrap().clone(), + filter: matches.get_one::(OPT_FILTER).cloned(), strategy, verbose: matches.value_source(OPT_VERBOSE) == Some(ValueSource::CommandLine), separator, diff --git a/src/uu/sum/src/sum.rs b/src/uu/sum/src/sum.rs index 4616274d0..38ad3964e 100644 --- a/src/uu/sum/src/sum.rs +++ b/src/uu/sum/src/sum.rs @@ -107,7 +107,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; let files: Vec = match matches.get_many::(options::FILE) { - Some(v) => v.clone().map(|v| v.to_owned()).collect(), + Some(v) => v.cloned().collect(), None => vec!["-".to_owned()], }; diff --git a/src/uu/tail/src/follow/files.rs b/src/uu/tail/src/follow/files.rs index e4f980267..d1aa0aed6 100644 --- a/src/uu/tail/src/follow/files.rs +++ b/src/uu/tail/src/follow/files.rs @@ -40,7 +40,7 @@ impl FileHandling { pub fn insert(&mut self, k: &Path, v: PathData, update_last: bool) { let k = Self::canonicalize_path(k); if update_last { - self.last = Some(k.to_owned()); + self.last = Some(k.clone()); } let _ = self.map.insert(k, v); } diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index fbda27aa0..1836a797a 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -279,7 +279,7 @@ impl Observer { if !path.is_file() { continue; } - let mut path = path.to_owned(); + let mut path = path.clone(); if path.is_relative() { path = std::env::current_dir()?.join(path); } @@ -345,7 +345,7 @@ impl Observer { show_error!("{}: file truncated", display_name); self.files.update_reader(event_path)?; } - paths.push(event_path.to_owned()); + paths.push(event_path.clone()); } else if !is_tailable && old_md.is_tailable() { if pd.reader.is_some() { self.files.reset_reader(event_path); @@ -359,7 +359,7 @@ impl Observer { } else if is_tailable { show_error!( "{} has appeared; following new file", display_name.quote()); self.files.update_reader(event_path)?; - paths.push(event_path.to_owned()); + paths.push(event_path.clone()); } else if settings.retry { if self.follow_descriptor() { show_error!( @@ -403,7 +403,7 @@ impl Observer { "{} cannot be used, reverting to polling", text::BACKEND ); - self.orphans.push(event_path.to_owned()); + self.orphans.push(event_path.clone()); let _ = self.watcher_rx.as_mut().unwrap().unwatch(event_path); } } else { @@ -451,7 +451,7 @@ impl Observer { if self.follow_descriptor() { let new_path = event.paths.last().unwrap(); - paths.push(new_path.to_owned()); + paths.push(new_path.clone()); let new_data = PathData::from_other_with_path(self.files.remove(event_path), new_path); self.files.insert( diff --git a/src/uu/test/src/parser.rs b/src/uu/test/src/parser.rs index 2b847fa15..23a2d7cf6 100644 --- a/src/uu/test/src/parser.rs +++ b/src/uu/test/src/parser.rs @@ -164,7 +164,7 @@ impl Parser { /// The stream is unchanged and will return the same Symbol on subsequent /// calls to `next()` or `peek()`. fn peek(&mut self) -> Symbol { - Symbol::new(self.tokens.peek().map(|s| s.to_os_string())) + Symbol::new(self.tokens.peek().cloned()) } /// Test if the next token in the stream is a BOOLOP (-a or -o), without