From 989da5a11bb8254fb2627bbbed3a736cf1f0dfc4 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 2 May 2024 15:14:46 +0200 Subject: [PATCH] clippy: fix warnings introduced with Rust 1.78 --- src/uu/cp/src/cp.rs | 9 +++++---- src/uu/csplit/src/csplit.rs | 12 ++++-------- src/uu/csplit/src/patterns.rs | 14 +++++++------- src/uu/df/src/filesystem.rs | 6 +++--- src/uu/env/src/env.rs | 6 +++--- src/uu/factor/src/factor.rs | 4 ++-- src/uu/hashsum/src/hashsum.rs | 10 +++++----- src/uu/kill/src/kill.rs | 2 +- src/uu/nl/src/helper.rs | 2 +- src/uu/ptx/src/ptx.rs | 2 +- src/uu/tail/src/follow/watch.rs | 1 + 11 files changed, 33 insertions(+), 35 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index cb3275ff9c4..c9d2783a4e4 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1120,6 +1120,7 @@ fn parse_path_args( }; if options.strip_trailing_slashes { + #[allow(clippy::assigning_clones)] for source in &mut paths { *source = source.components().as_path().to_owned(); } @@ -1617,8 +1618,8 @@ fn handle_existing_dest( // linking. if options.preserve_hard_links() - // only try to remove dest file only if the current source - // is hardlink to a file that is already copied + // only try to remove dest file only if the current source + // is hardlink to a file that is already copied && copied_files.contains_key( &FileInformation::from_path( source, @@ -1734,7 +1735,7 @@ fn handle_copy_mode( dest: &Path, options: &Options, context: &str, - source_metadata: Metadata, + source_metadata: &Metadata, symlinked_files: &mut HashSet, source_in_command_line: bool, ) -> CopyResult<()> { @@ -2053,7 +2054,7 @@ fn copy_file( dest, options, context, - source_metadata, + &source_metadata, symlinked_files, source_in_command_line, )?; diff --git a/src/uu/csplit/src/csplit.rs b/src/uu/csplit/src/csplit.rs index cd55ef7dfcf..7d625d925fa 100644 --- a/src/uu/csplit/src/csplit.rs +++ b/src/uu/csplit/src/csplit.rs @@ -86,17 +86,13 @@ impl CsplitOptions { /// - [`CsplitError::MatchNotFound`] if no line matched a regular expression. /// - [`CsplitError::MatchNotFoundOnRepetition`], like previous but after applying the pattern /// more than once. -pub fn csplit( - options: &CsplitOptions, - patterns: Vec, - input: T, -) -> Result<(), CsplitError> +pub fn csplit(options: &CsplitOptions, patterns: &[String], input: T) -> Result<(), CsplitError> where T: BufRead, { let mut input_iter = InputSplitter::new(input.lines().enumerate()); let mut split_writer = SplitWriter::new(options); - let patterns: Vec = patterns::get_patterns(&patterns[..])?; + let patterns: Vec = patterns::get_patterns(patterns)?; let ret = do_csplit(&mut split_writer, patterns, &mut input_iter); // consume the rest, unless there was an error @@ -568,7 +564,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let options = CsplitOptions::new(&matches); if file_name == "-" { let stdin = io::stdin(); - Ok(csplit(&options, patterns, stdin.lock())?) + Ok(csplit(&options, &patterns, stdin.lock())?) } else { let file = File::open(file_name) .map_err_context(|| format!("cannot access {}", file_name.quote()))?; @@ -578,7 +574,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { if !file_metadata.is_file() { return Err(CsplitError::NotRegularFile(file_name.to_string()).into()); } - Ok(csplit(&options, patterns, BufReader::new(file))?) + Ok(csplit(&options, &patterns, BufReader::new(file))?) } } diff --git a/src/uu/csplit/src/patterns.rs b/src/uu/csplit/src/patterns.rs index 6e7483b7f9f..bd6c4fbfaef 100644 --- a/src/uu/csplit/src/patterns.rs +++ b/src/uu/csplit/src/patterns.rs @@ -25,14 +25,14 @@ pub enum Pattern { SkipToMatch(Regex, i32, ExecutePattern), } -impl ToString for Pattern { - fn to_string(&self) -> String { +impl std::fmt::Display for Pattern { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::UpToLine(n, _) => n.to_string(), - Self::UpToMatch(regex, 0, _) => format!("/{}/", regex.as_str()), - Self::UpToMatch(regex, offset, _) => format!("/{}/{:+}", regex.as_str(), offset), - Self::SkipToMatch(regex, 0, _) => format!("%{}%", regex.as_str()), - Self::SkipToMatch(regex, offset, _) => format!("%{}%{:+}", regex.as_str(), offset), + Self::UpToLine(n, _) => write!(f, "{n}"), + Self::UpToMatch(regex, 0, _) => write!(f, "/{}/", regex.as_str()), + Self::UpToMatch(regex, offset, _) => write!(f, "/{}/{:+}", regex.as_str(), offset), + Self::SkipToMatch(regex, 0, _) => write!(f, "%{}%", regex.as_str()), + Self::SkipToMatch(regex, offset, _) => write!(f, "%{}%{:+}", regex.as_str(), offset), } } } diff --git a/src/uu/df/src/filesystem.rs b/src/uu/df/src/filesystem.rs index ef5107958a2..f3620b6e2f3 100644 --- a/src/uu/df/src/filesystem.rs +++ b/src/uu/df/src/filesystem.rs @@ -222,13 +222,13 @@ mod tests { #[test] fn test_dev_name_match() { let tmp = tempfile::TempDir::new().expect("Failed to create temp dir"); - let dev_name = std::fs::canonicalize(tmp.path()) + let mut dev_name = std::fs::canonicalize(tmp.path()) .expect("Failed to canonicalize tmp path") .to_string_lossy() .to_string(); - let mut mount_info = mount_info("/foo"); - mount_info.dev_name = dev_name.clone(); + let mount_info = mount_info("/foo"); + mount_info.dev_name.clone_into(&mut dev_name); let mounts = [mount_info]; let actual = mount_info_from_path(&mounts, dev_name, false).unwrap(); assert!(mount_info_eq(actual, &mounts[0])); diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 342fb737d63..6fad45e5e56 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -104,7 +104,7 @@ fn load_config_file(opts: &mut Options) -> UResult<()> { for (_, prop) in &conf { // ignore all INI section lines (treat them as comments) - for (key, value) in prop.iter() { + for (key, value) in prop { env::set_var(key, value); } } @@ -371,7 +371,7 @@ impl EnvAppData { // no program provided, so just dump all env vars to stdout print_env(opts.line_ending); } else { - return self.run_program(opts, self.do_debug_printing); + return self.run_program(&opts, self.do_debug_printing); } Ok(()) @@ -379,7 +379,7 @@ impl EnvAppData { fn run_program( &mut self, - opts: Options<'_>, + opts: &Options<'_>, do_debug_printing: bool, ) -> Result<(), Box> { let prog = Cow::from(opts.program[0]); diff --git a/src/uu/factor/src/factor.rs b/src/uu/factor/src/factor.rs index b56dbf3d108..41fd860b3ce 100644 --- a/src/uu/factor/src/factor.rs +++ b/src/uu/factor/src/factor.rs @@ -51,14 +51,14 @@ fn print_factors_str( )); } - write_result(w, x, factorization, print_exponents).map_err_context(|| "write error".into())?; + write_result(w, &x, factorization, print_exponents).map_err_context(|| "write error".into())?; Ok(()) } fn write_result( w: &mut io::BufWriter, - x: BigUint, + x: &BigUint, factorization: BTreeMap, print_exponents: bool, ) -> io::Result<()> { diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index d4c5aacbb6a..708596096f9 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -831,27 +831,27 @@ where if !options.status && !skip_summary { match bad_format.cmp(&1) { Ordering::Equal => { - show_warning_caps!("{} line is improperly formatted", bad_format) + show_warning_caps!("{} line is improperly formatted", bad_format); } Ordering::Greater => { - show_warning_caps!("{} lines are improperly formatted", bad_format) + show_warning_caps!("{} lines are improperly formatted", bad_format); } Ordering::Less => {} }; match failed_cksum.cmp(&1) { Ordering::Equal => { - show_warning_caps!("{} computed checksum did NOT match", failed_cksum) + show_warning_caps!("{} computed checksum did NOT match", failed_cksum); } Ordering::Greater => { - show_warning_caps!("{} computed checksums did NOT match", failed_cksum) + show_warning_caps!("{} computed checksums did NOT match", failed_cksum); } Ordering::Less => {} }; match failed_open_file.cmp(&1) { Ordering::Equal => { - show_warning_caps!("{} listed file could not be read", failed_open_file) + show_warning_caps!("{} listed file could not be read", failed_open_file); } Ordering::Greater => { show_warning_caps!("{} listed files could not be read", failed_open_file); diff --git a/src/uu/kill/src/kill.rs b/src/uu/kill/src/kill.rs index 5446a7f1826..6048acfb96a 100644 --- a/src/uu/kill/src/kill.rs +++ b/src/uu/kill/src/kill.rs @@ -193,7 +193,7 @@ fn list(signals: &Vec) { } else { for signal in signals { if let Err(e) = print_signal(signal) { - uucore::show!(e) + uucore::show!(e); } } } diff --git a/src/uu/nl/src/helper.rs b/src/uu/nl/src/helper.rs index ee3f3a0a95d..3e5a96b9ca2 100644 --- a/src/uu/nl/src/helper.rs +++ b/src/uu/nl/src/helper.rs @@ -23,7 +23,7 @@ pub fn parse_options(settings: &mut crate::Settings, opts: &clap::ArgMatches) -> }; } if let Some(val) = opts.get_one::(options::NUMBER_SEPARATOR) { - settings.number_separator = val.clone(); + settings.number_separator.clone_from(val); } settings.number_format = opts .get_one::(options::NUMBER_FORMAT) diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index b952da92931..0fb711798d0 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -223,7 +223,7 @@ fn get_config(matches: &clap::ArgMatches) -> UResult { if matches.get_flag(options::TRADITIONAL) { config.gnu_ext = false; config.format = OutFormat::Roff; - config.context_regex = "[^ \t\n]+".to_owned(); + "[^ \t\n]+".clone_into(&mut config.context_regex); } else { return Err(PtxError::NotImplemented("GNU extensions").into()); } diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index 1836a797a96..2e0fc651c6f 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -45,6 +45,7 @@ impl WatcherRx { Tested for notify::InotifyWatcher and for notify::PollWatcher. */ if let Some(parent) = path.parent() { + #[allow(clippy::assigning_clones)] if parent.is_dir() { path = parent.to_owned(); } else {