From dabee0675f45fccbfc19b10043e3d98fc1f3b284 Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Tue, 14 Jan 2025 12:09:50 -0500 Subject: [PATCH 1/2] chore: Apply Clippy lint `clippy::clear_with_drain` --- components/clarinet-cli/src/lsp/native_bridge.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/clarinet-cli/src/lsp/native_bridge.rs b/components/clarinet-cli/src/lsp/native_bridge.rs index b4e049dd0..8a8843186 100644 --- a/components/clarinet-cli/src/lsp/native_bridge.rs +++ b/components/clarinet-cli/src/lsp/native_bridge.rs @@ -239,7 +239,7 @@ impl LanguageServer for LspNativeBridge { notification = notification_response.notification.take(); } } - for (location, mut diags) in aggregated_diagnostics.drain(..) { + for (location, mut diags) in aggregated_diagnostics.into_iter() { if let Ok(url) = location.to_url_string() { self.client .publish_diagnostics( @@ -282,7 +282,7 @@ impl LanguageServer for LspNativeBridge { } } - for (location, mut diags) in aggregated_diagnostics.drain(..) { + for (location, mut diags) in aggregated_diagnostics.into_iter() { if let Ok(url) = location.to_url_string() { self.client .publish_diagnostics( From 1de01a86f54903e8fd947585b76c66df89e376ee Mon Sep 17 00:00:00 2001 From: Jeff Bencin Date: Tue, 14 Jan 2025 12:55:10 -0500 Subject: [PATCH 2/2] chore: Apply Clippy lint `clippy::redundant_clone` --- components/clarinet-cli/src/frontend/cli.rs | 6 ++-- components/clarinet-cli/src/frontend/dap.rs | 2 +- .../clarinet-cli/src/generate/project.rs | 2 +- .../src/diagnostic_digest.rs | 2 +- .../clarinet-deployments/src/onchain/mod.rs | 4 +-- .../clarinet-files/src/project_manifest.rs | 2 +- components/clarity-lsp/src/common/backend.rs | 2 +- .../src/common/requests/completion.rs | 4 +-- components/clarity-lsp/src/common/state.rs | 2 +- .../clarity-repl/src/repl/debug/dap/mod.rs | 4 +-- .../clarity-repl/src/repl/diagnostic.rs | 6 ++-- components/clarity-repl/src/repl/session.rs | 28 ++++++++----------- components/stacks-network/src/lib.rs | 4 +-- components/stacks-network/src/orchestrator.rs | 11 ++++---- components/stacks-network/src/ui/ui.rs | 2 +- components/stacks-rpc-client/src/crypto.rs | 4 +-- 16 files changed, 40 insertions(+), 45 deletions(-) diff --git a/components/clarinet-cli/src/frontend/cli.rs b/components/clarinet-cli/src/frontend/cli.rs index 3d5b22d6b..64e08534b 100644 --- a/components/clarinet-cli/src/frontend/cli.rs +++ b/components/clarinet-cli/src/frontend/cli.rs @@ -473,7 +473,7 @@ pub fn main() { } }; clap_complete::generate(cmd.shell, &mut app, "clarinet", &mut file); - println!("{} {}", green!("Created file"), file_name.clone()); + println!("{} {}", green!("Created file"), file_name); println!("Check your shell's documentation for details about using this file to enable completions for clarinet"); } Command::New(project_opts) => { @@ -925,11 +925,11 @@ pub fn main() { yellow!("Updated Clarinet.toml"), green!(format!("{}", cmd.contract_id)) ), - manifest_location: manifest.location.clone(), + manifest_location: manifest.location, contracts_to_rm: vec![], contracts_to_add: HashMap::new(), requirements_to_add: vec![RequirementConfig { - contract_id: cmd.contract_id.clone(), + contract_id: cmd.contract_id, }], }; if !execute_changes(vec![Changes::EditTOML(change)]) { diff --git a/components/clarinet-cli/src/frontend/dap.rs b/components/clarinet-cli/src/frontend/dap.rs index a0ae3bd6a..87670e1b1 100644 --- a/components/clarinet-cli/src/frontend/dap.rs +++ b/components/clarinet-cli/src/frontend/dap.rs @@ -41,7 +41,7 @@ pub fn run_dap() -> Result<(), String> { } // Begin execution of the expression in debug mode - match session.eval_with_hooks(expression.clone(), Some(vec![&mut dap]), false) { + match session.eval_with_hooks(expression, Some(vec![&mut dap]), false) { Ok(_result) => Ok(()), Err(_diagnostics) => Err("unable to interpret expression".to_string()), } diff --git a/components/clarinet-cli/src/generate/project.rs b/components/clarinet-cli/src/generate/project.rs index bf674ee3b..bcc0caba9 100644 --- a/components/clarinet-cli/src/generate/project.rs +++ b/components/clarinet-cli/src/generate/project.rs @@ -26,7 +26,7 @@ impl GetChangesForNewProject { telemetry_enabled: bool, ) -> Self { let project_path = if use_current_dir { - project_path.clone() + project_path } else { format!("{}/{}", project_path, project_name) }; diff --git a/components/clarinet-deployments/src/diagnostic_digest.rs b/components/clarinet-deployments/src/diagnostic_digest.rs index 0a5931559..58ebf1d56 100644 --- a/components/clarinet-deployments/src/diagnostic_digest.rs +++ b/components/clarinet-deployments/src/diagnostic_digest.rs @@ -100,7 +100,7 @@ impl DiagnosticsDigest { warnings, total, contracts_checked, - message: outputs.join("\n").to_string(), + message: outputs.join("\n"), } } diff --git a/components/clarinet-deployments/src/onchain/mod.rs b/components/clarinet-deployments/src/onchain/mod.rs index 5f09aad98..61b8769bd 100644 --- a/components/clarinet-deployments/src/onchain/mod.rs +++ b/components/clarinet-deployments/src/onchain/mod.rs @@ -147,8 +147,8 @@ pub fn encode_contract_call( let payload = TransactionContractCall { contract_name: contract_id.name.clone(), address: StacksAddress::from(contract_id.issuer.clone()), - function_name: function_name.clone(), - function_args: function_args.clone(), + function_name, + function_args, }; sign_transaction_payload( account, diff --git a/components/clarinet-files/src/project_manifest.rs b/components/clarinet-files/src/project_manifest.rs index 895c629f3..79bfe979e 100644 --- a/components/clarinet-files/src/project_manifest.rs +++ b/components/clarinet-files/src/project_manifest.rs @@ -237,7 +237,7 @@ impl ProjectManifest { }; let project = ProjectConfig { - name: project_name.clone(), + name: project_name, requirements: None, description: project_manifest_file .project diff --git a/components/clarity-lsp/src/common/backend.rs b/components/clarity-lsp/src/common/backend.rs index 20d5293b6..05653e382 100644 --- a/components/clarity-lsp/src/common/backend.rs +++ b/components/clarity-lsp/src/common/backend.rs @@ -166,7 +166,7 @@ pub async fn process_notification( }; let issuer = metadata.and_then(|(_, deployer)| match deployer { - ContractDeployer::ContractIdentifier(id) => Some(id.issuer.to_owned()), + ContractDeployer::ContractIdentifier(id) => Some(id.issuer), _ => None, }); diff --git a/components/clarity-lsp/src/common/requests/completion.rs b/components/clarity-lsp/src/common/requests/completion.rs index cfff2f463..e10aa96f9 100644 --- a/components/clarity-lsp/src/common/requests/completion.rs +++ b/components/clarity-lsp/src/common/requests/completion.rs @@ -534,7 +534,7 @@ pub fn build_default_native_keywords_list(version: ClarityVersion) -> Vec Vec String { match level { - Level::Note => blue!("note:").to_string(), - Level::Warning => yellow!("warning:").to_string(), - Level::Error => red!("error:").to_string(), + Level::Note => blue!("note:"), + Level::Warning => yellow!("warning:"), + Level::Error => red!("error:"), } } diff --git a/components/clarity-repl/src/repl/session.rs b/components/clarity-repl/src/repl/session.rs index 6f82d7f5d..607f6a821 100644 --- a/components/clarity-repl/src/repl/session.rs +++ b/components/clarity-repl/src/repl/session.rs @@ -305,7 +305,7 @@ impl Session { ) { Ok((mut output, result)) => { if let EvaluationResult::Contract(contract_result) = result.result.clone() { - let snippet = format!("→ .{} contract successfully stored. Use (contract-call? ...) for invoking the public functions:", contract_result.contract.contract_identifier.clone()); + let snippet = format!("→ .{} contract successfully stored. Use (contract-call? ...) for invoking the public functions:", contract_result.contract.contract_identifier); output.push(green!(snippet)); }; (output, result.cost.clone(), Ok(result)) @@ -447,7 +447,7 @@ impl Session { ) { Ok((mut output, result)) => { if let EvaluationResult::Contract(contract_result) = result.result { - let snippet = format!("→ .{} contract successfully stored. Use (contract-call? ...) for invoking the public functions:", contract_result.contract.contract_identifier.clone()); + let snippet = format!("→ .{} contract successfully stored. Use (contract-call? ...) for invoking the public functions:", contract_result.contract.contract_identifier); output.push(snippet.green().to_string()); }; output @@ -541,8 +541,8 @@ impl Session { amount: u64, recipient: &str, ) -> Result> { - let snippet = format!("(stx-transfer? u{} tx-sender '{})", amount, recipient); - self.eval(snippet.clone(), false) + let snippet = format!("(stx-transfer? u{amount} tx-sender '{recipient})"); + self.eval(snippet, false) } pub fn deploy_contract( @@ -668,15 +668,13 @@ impl Session { let result = self .interpreter - .run(&contract.clone(), None, cost_track, Some(hooks)); + .run(&contract, None, cost_track, Some(hooks)); match result { Ok(result) => { if let EvaluationResult::Contract(contract_result) = &result.result { - self.contracts.insert( - contract_identifier.clone(), - contract_result.contract.clone(), - ); + self.contracts + .insert(contract_identifier, contract_result.contract.clone()); }; Ok(result) } @@ -702,15 +700,13 @@ impl Session { let result = self .interpreter - .run(&contract.clone(), None, cost_track, eval_hooks); + .run(&contract, None, cost_track, eval_hooks); match result { Ok(result) => { if let EvaluationResult::Contract(contract_result) = &result.result { - self.contracts.insert( - contract_identifier.clone(), - contract_result.contract.clone(), - ); + self.contracts + .insert(contract_identifier, contract_result.contract.clone()); }; Ok(result) } @@ -730,7 +726,7 @@ impl Session { let mut keys = self .api_reference .keys() - .map(|k| k.to_string()) + .map(String::from) .collect::>(); keys.sort(); keys @@ -740,7 +736,7 @@ impl Session { let mut keys = self .keywords_reference .keys() - .map(|k| k.to_string()) + .map(String::from) .collect::>(); keys.sort(); keys diff --git a/components/stacks-network/src/lib.rs b/components/stacks-network/src/lib.rs index a3fbe554a..8a823e6cb 100644 --- a/components/stacks-network/src/lib.rs +++ b/components/stacks-network/src/lib.rs @@ -202,8 +202,8 @@ async fn do_run_devnet( } } else { let moved_orchestrator_terminator_tx = orchestrator_terminator_tx.clone(); - let moved_observer_command_tx = observer_command_tx.clone(); - let moved_mining_command_tx = mining_command_tx.clone(); + let moved_observer_command_tx = observer_command_tx; + let moved_mining_command_tx = mining_command_tx; let _ = ctrlc::set_handler(move || { let _ = moved_orchestrator_terminator_tx.send(true); let _ = moved_observer_command_tx.send(ObserverCommand::Terminate); diff --git a/components/stacks-network/src/orchestrator.rs b/components/stacks-network/src/orchestrator.rs index 0970ac9cc..37cf8d9dd 100644 --- a/components/stacks-network/src/orchestrator.rs +++ b/components/stacks-network/src/orchestrator.rs @@ -1342,7 +1342,7 @@ start_height = {epoch_3_1} .id; ctx.try_log(|logger| slog::info!(logger, "Created container stacks-node: {}", container)); - self.stacks_node_container_id = Some(container.clone()); + self.stacks_node_container_id = Some(container); Ok(()) } @@ -1504,7 +1504,7 @@ db_path = "stacks-signer-{signer_id}.sqlite" container ) }); - self.stacks_signers_containers_ids.push(container.clone()); + self.stacks_signers_containers_ids.push(container); Ok(()) } @@ -1512,9 +1512,8 @@ db_path = "stacks-signer-{signer_id}.sqlite" pub async fn boot_stacks_signer_container(&mut self, signer_id: u32) -> Result<(), String> { let container = self.stacks_signers_containers_ids[signer_id as usize].clone(); - let docker = match &self.docker_client { - Some(ref docker) => docker, - _ => return Err("unable to get Docker client".into()), + let Some(docker) = &self.docker_client else { + return Err("unable to get Docker client".into()); }; docker @@ -1750,7 +1749,7 @@ events_keys = ["*"] .id; ctx.try_log(|logger| slog::info!(logger, "Created container subnet-node: {}", container)); - self.subnet_node_container_id = Some(container.clone()); + self.subnet_node_container_id = Some(container); Ok(()) } diff --git a/components/stacks-network/src/ui/ui.rs b/components/stacks-network/src/ui/ui.rs index 73212b690..3c9da69a4 100644 --- a/components/stacks-network/src/ui/ui.rs +++ b/components/stacks-network/src/ui/ui.rs @@ -343,7 +343,7 @@ fn draw_help(f: &mut Frame, app: &mut App, area: Rect) { // let help = // " ⬅️ ➡️ Explore blocks ⬆️ ⬇️ Explore transactions 0️⃣ Genesis Reset"; let help = format!(" ⬅️ ➡️ Explore blocks Path: {}", app.devnet_path); - let paragraph = Paragraph::new(help.clone()) + let paragraph = Paragraph::new(help) .style(Style::default().fg(Color::White)) .block(Block::default().borders(Borders::NONE)); diff --git a/components/stacks-rpc-client/src/crypto.rs b/components/stacks-rpc-client/src/crypto.rs index 4c031f52d..72ba8890f 100644 --- a/components/stacks-rpc-client/src/crypto.rs +++ b/components/stacks-rpc-client/src/crypto.rs @@ -125,8 +125,8 @@ pub fn encode_contract_call( let payload = TransactionContractCall { contract_name: contract_id.name.clone(), address: StacksAddress::from(contract_id.issuer.clone()), - function_name: function_name.clone(), - function_args: function_args.clone(), + function_name, + function_args, }; sign_transaction_payload( wallet,