From 06a14c4a76204afc915cbcbd4c2fd5e644d89929 Mon Sep 17 00:00:00 2001 From: xtqqczze <45661989+xtqqczze@users.noreply.github.com> Date: Sun, 4 Jan 2026 01:35:53 +0000 Subject: [PATCH] clippy: fix assigning_clones lint https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones Closes #12267 --- Cargo.toml | 1 + src/builtins/set.rs | 12 +++++++----- src/history/history.rs | 2 +- src/parse_execution.rs | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e6058976..7d3416f2b 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] +assigning_clones = "warn" implicit_clone = "warn" cloned_instead_of_copied = "warn" len_without_is_empty = "allow" # we're not a library crate diff --git a/src/builtins/set.rs b/src/builtins/set.rs index 50fa07206..fa628d111 100644 --- a/src/builtins/set.rs +++ b/src/builtins/set.rs @@ -890,7 +890,7 @@ fn new_var_values( // So do not use the given variable: we must re-fetch it. // TODO: this races under concurrent execution. if let Some(existing) = vars.get(varname) { - result = existing.as_list().to_owned(); + existing.as_list().clone_into(&mut result); } if opts.prepend { @@ -914,10 +914,12 @@ fn new_var_values_by_index(split: &SplitVar, argv: &[&wstr]) -> Vec { // Inherit any existing values. // Note unlike the append/prepend case, we start with a variable in the same scope as we are // setting. - let mut result = vec![]; - if let Some(var) = split.var.as_ref() { - result = var.as_list().to_owned(); - } + let mut result = split + .var + .as_ref() + .map(EnvVar::as_list) + .unwrap_or_default() + .to_owned(); // For each (index, argument) pair, set the element in our `result` to the replacement string. // Extend the list with empty strings as needed. The indexes are 1-based. diff --git a/src/history/history.rs b/src/history/history.rs index 45a2b5837..74dadc3b8 100644 --- a/src/history/history.rs +++ b/src/history/history.rs @@ -281,7 +281,7 @@ fn merge(&mut self, item: &HistoryItem) -> bool { // Ok, merge this item. self.creation_timestamp = self.creation_timestamp.max(item.creation_timestamp); if self.required_paths.len() < item.required_paths.len() { - self.required_paths = item.required_paths.clone(); + self.required_paths.clone_from(&item.required_paths); } true } diff --git a/src/parse_execution.rs b/src/parse_execution.rs index 5b4b26fc5..dda145900 100644 --- a/src/parse_execution.rs +++ b/src/parse_execution.rs @@ -453,7 +453,7 @@ fn infinite_recursive_statement_in_job_list<'b>( }); if infinite_recursive_statement.is_some() { - *out_func_name = forbidden_function_name.to_owned(); + forbidden_function_name.clone_into(out_func_name); } // may be none @@ -1865,7 +1865,7 @@ fn setup_group(&self, ctx: &OperationContext<'_>, j: &mut Job) { .is_some_and(|job_group| job_group.has_job_id() || !j.wants_job_id()) && !j.is_initially_background() { - j.group = ctx.job_group.clone(); + j.group.clone_from(&ctx.job_group); return; }