From 2d6db3f98096157065973e2b09595aa96ae27ebc Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Wed, 31 Dec 2025 17:13:01 +0000 Subject: [PATCH] clippy: fix implicit_clone lint https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone Closes #12245 --- Cargo.toml | 1 + src/builtins/argparse.rs | 2 +- src/builtins/bind.rs | 4 ++-- src/builtins/string/match.rs | 2 +- src/env_universal_common.rs | 10 +++++----- src/expand.rs | 4 ++-- src/highlight/file_tester.rs | 2 +- src/history/history.rs | 2 +- src/path.rs | 6 +++--- src/reader/reader.rs | 8 ++------ src/wildcard.rs | 4 ++-- 11 files changed, 21 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 601dd4140..6e6058976 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -184,6 +184,7 @@ rust.unstable_name_collisions = "allow" rustdoc.private_intra_doc_links = "allow" [workspace.lints.clippy] +implicit_clone = "warn" cloned_instead_of_copied = "warn" len_without_is_empty = "allow" # we're not a library crate let_and_return = "allow" diff --git a/src/builtins/argparse.rs b/src/builtins/argparse.rs index cfcbbbc43..f2293b7f6 100644 --- a/src/builtins/argparse.rs +++ b/src/builtins/argparse.rs @@ -196,7 +196,7 @@ fn parse_exclusive_args(opts: &mut ArgParseCmdOpts, streams: &mut IoStreams) -> } // Store the set of exclusive flags for use when parsing the supplied set of arguments. - opts.exclusive_flag_sets.push(exclusive_set.to_vec()); + opts.exclusive_flag_sets.push(exclusive_set.clone()); } Ok(SUCCESS) } diff --git a/src/builtins/bind.rs b/src/builtins/bind.rs index a521e379d..ce096c7c4 100644 --- a/src/builtins/bind.rs +++ b/src/builtins/bind.rs @@ -370,8 +370,8 @@ fn insert( if self.add( seq, &argv[optind + 1..], - self.opts.bind_mode.to_owned(), - self.opts.sets_bind_mode.to_owned(), + self.opts.bind_mode.clone(), + self.opts.sets_bind_mode.clone(), self.opts.user, streams, ) { diff --git a/src/builtins/string/match.rs b/src/builtins/string/match.rs index 29650640c..5a2e3149f 100644 --- a/src/builtins/string/match.rs +++ b/src/builtins/string/match.rs @@ -295,7 +295,7 @@ fn populate_captures_from_match<'a>( // empty/null members so we're going to have to use an empty string as the // sentinel value. - if let Some(m) = cg.as_ref().and_then(|cg| cg.name(&name.to_string())) { + if let Some(m) = cg.as_ref().and_then(|cg| cg.name(&name.clone())) { captures.push(WString::from(m.as_bytes())); } else if opts.all { captures.push(WString::new()); diff --git a/src/env_universal_common.rs b/src/env_universal_common.rs index 420b73ede..c199b622d 100644 --- a/src/env_universal_common.rs +++ b/src/env_universal_common.rs @@ -862,7 +862,7 @@ fn test_universal() { let mut handles = Vec::new(); for i in 0..threads { - let path = test_path.to_owned(); + let path = test_path.clone(); handles.push(std::thread::spawn(move || { test_universal_helper(i, &path); })); @@ -873,7 +873,7 @@ fn test_universal() { } let mut uvars = EnvUniversal::new(); - uvars.initialize_at_path(test_path.to_owned()); + uvars.initialize_at_path(test_path.clone()); for i in 0..threads { for j in 0..UVARS_PER_THREAD { @@ -1037,11 +1037,11 @@ fn test_universal_callbacks() { let mut uvars1 = EnvUniversal::new(); let mut uvars2 = EnvUniversal::new(); let mut callbacks = uvars1 - .initialize_at_path(test_path.to_owned()) + .initialize_at_path(test_path.clone()) .unwrap_or_default(); callbacks.append( &mut uvars2 - .initialize_at_path(test_path.to_owned()) + .initialize_at_path(test_path.clone()) .unwrap_or_default(), ); @@ -1134,7 +1134,7 @@ fn test_universal_ok_to_save() { let mut uvars = EnvUniversal::new(); uvars - .initialize_at_path(test_path.to_owned()) + .initialize_at_path(test_path.clone()) .unwrap_or_default(); assert!(!uvars.is_ok_to_save(), "Should not be OK to save"); uvars.sync(); diff --git a/src/expand.rs b/src/expand.rs index 7b6cb647d..084063419 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -737,7 +737,7 @@ fn expand_variables( // here, So tmp < 1 means it's definitely not in. // Note we are 1-based. if item_index >= 1 && item_index <= all_var_items.len() { - var_item_list.push(all_var_items[item_index - 1].to_owned()); + var_item_list.push(all_var_items[item_index - 1].clone()); } } } @@ -1038,7 +1038,7 @@ pub fn expand_cmdsubst( continue; } // -1 to convert from 1-based slice index to 0-based vector index. - sub_res2.push(sub_res[idx as usize - 1].to_owned()); + sub_res2.push(sub_res[idx as usize - 1].clone()); } sub_res = sub_res2; } diff --git a/src/highlight/file_tester.rs b/src/highlight/file_tester.rs index 2647d8e7e..32f986a08 100644 --- a/src/highlight/file_tester.rs +++ b/src/highlight/file_tester.rs @@ -88,7 +88,7 @@ pub fn test_path(&self, token: &wstr, prefix: bool) -> bool { is_potential_path( &token, prefix, - &[self.working_directory.to_owned()], + std::slice::from_ref(&self.working_directory), self.ctx, PathFlags { expand_tilde: true, diff --git a/src/history/history.rs b/src/history/history.rs index 31f1461b3..737face06 100644 --- a/src/history/history.rs +++ b/src/history/history.rs @@ -451,7 +451,7 @@ fn compact_new_items(&mut self) { continue; } - if !seen.insert(item.contents.to_owned()) { + if !seen.insert(item.contents.clone()) { // This item was not inserted because it was already in the set, so delete the item at // this index. self.new_items.remove(idx); diff --git a/src/path.rs b/src/path.rs index e07451a60..5e1176866 100644 --- a/src/path.rs +++ b/src/path.rs @@ -24,7 +24,7 @@ pub fn path_get_config() -> Option { let dir = get_config_directory(); if dir.success() { - Some(dir.path.to_owned()) + Some(dir.path.clone()) } else { None } @@ -40,7 +40,7 @@ pub fn path_get_config() -> Option { pub fn path_get_data() -> Option { let dir = get_data_directory(); if dir.success() { - Some(dir.path.to_owned()) + Some(dir.path.clone()) } else { None } @@ -57,7 +57,7 @@ pub fn path_get_data() -> Option { pub fn path_get_cache() -> Option { let dir = get_cache_directory(); if dir.success() { - Some(dir.path.to_owned()) + Some(dir.path.clone()) } else { None } diff --git a/src/reader/reader.rs b/src/reader/reader.rs index 58552ee43..9f329d891 100644 --- a/src/reader/reader.rs +++ b/src/reader/reader.rs @@ -5989,14 +5989,10 @@ fn reader_run_command(parser: &Parser, cmd: &wstr) -> EvalRes { // Provide values for `status current-command` and `status current-commandline` if !ft.is_empty() { - parser.libdata_mut().status_vars.command = ft.to_owned(); + parser.libdata_mut().status_vars.command = ft.clone(); parser.libdata_mut().status_vars.commandline = cmd.to_owned(); // Also provide a value for the deprecated fish 2.0 $_ variable - parser.set_one( - L!("_"), - ParserEnvSetMode::new(EnvMode::GLOBAL), - ft.to_owned(), - ); + parser.set_one(L!("_"), ParserEnvSetMode::new(EnvMode::GLOBAL), ft.clone()); } reader_write_title(cmd, parser, true); diff --git a/src/wildcard.rs b/src/wildcard.rs index 580cf67c5..cfa109503 100644 --- a/src/wildcard.rs +++ b/src/wildcard.rs @@ -500,7 +500,7 @@ pub fn new( working_directory, completion_set: resolved_completions .iter() - .map(|c| c.completion.to_owned()) + .map(|c| c.completion.clone()) .collect(), visited_files: HashSet::new(), flags, @@ -943,7 +943,7 @@ fn descend_unique_hierarchy(&mut self, start_point: &mut WString) -> WString { break; } else if entry.is_dir() && unique_entry.is_empty() { // first candidate - unique_entry = entry.name.to_owned(); + unique_entry = entry.name.clone(); } else { // We either have two or more candidates, or the child is not a directory. We're // done.