Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Apply Clippy lints redundant_clone and clear_with_drain #1640

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)]) {
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-cli/src/frontend/dap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-cli/src/generate/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
Expand Down
4 changes: 2 additions & 2 deletions components/clarinet-cli/src/lsp/native_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-deployments/src/diagnostic_digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl DiagnosticsDigest {
warnings,
total,
contracts_checked,
message: outputs.join("\n").to_string(),
message: outputs.join("\n"),
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/clarinet-deployments/src/onchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/clarinet-files/src/project_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl ProjectManifest {
};

let project = ProjectConfig {
name: project_name.clone(),
name: project_name,
requirements: None,
description: project_manifest_file
.project
Expand Down
2 changes: 1 addition & 1 deletion components/clarity-lsp/src/common/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
4 changes: 2 additions & 2 deletions components/clarity-lsp/src/common/requests/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ pub fn build_default_native_keywords_list(version: ClarityVersion) -> Vec<Comple
kind: MarkupKind::Markdown,
value: api.description,
})),
insert_text: Some(api.snippet.clone()),
insert_text: Some(api.snippet),
insert_text_format: Some(InsertTextFormat::SNIPPET),
command: Some(command.clone()),
..Default::default()
Expand All @@ -559,7 +559,7 @@ pub fn build_default_native_keywords_list(version: ClarityVersion) -> Vec<Comple
kind: MarkupKind::Markdown,
value: api.description,
})),
insert_text: Some(api.snippet.clone()),
insert_text: Some(api.snippet),
insert_text_format: Some(InsertTextFormat::SNIPPET),
command: Some(command.clone()),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion components/clarity-lsp/src/common/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl EditorState {
Some(Hover {
contents: lsp_types::HoverContents::Markup(lsp_types::MarkupContent {
kind: lsp_types::MarkupKind::Markdown,
value: documentation.to_string(),
value: documentation,
}),
range: None,
})
Expand Down
4 changes: 2 additions & 2 deletions components/clarity-repl/src/repl/debug/dap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,8 @@ impl EvalHook for DAPDebugger {
} else {
let stack_frame = StackFrame {
id: (stack_trace.len() as i32 + 1),
name: current_function.to_string().clone(),
source: Some(source.clone()),
name: current_function.to_string(),
source: Some(source),
line: expr.span.start_line,
column: expr.span.start_column,
end_line: Some(expr.span.end_line),
Expand Down
6 changes: 3 additions & 3 deletions components/clarity-repl/src/repl/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use clarity::vm::diagnostic::{Diagnostic, Level};

fn level_to_string(level: &Level) -> 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:"),
}
}

Expand Down
28 changes: 12 additions & 16 deletions components/clarity-repl/src/repl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -541,8 +541,8 @@ impl Session {
amount: u64,
recipient: &str,
) -> Result<ExecutionResult, Vec<Diagnostic>> {
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(
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -730,7 +726,7 @@ impl Session {
let mut keys = self
.api_reference
.keys()
.map(|k| k.to_string())
.map(String::from)
.collect::<Vec<String>>();
keys.sort();
keys
Expand All @@ -740,7 +736,7 @@ impl Session {
let mut keys = self
.keywords_reference
.keys()
.map(|k| k.to_string())
.map(String::from)
.collect::<Vec<String>>();
keys.sort();
keys
Expand Down
4 changes: 2 additions & 2 deletions components/stacks-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 5 additions & 6 deletions components/stacks-network/src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down Expand Up @@ -1504,17 +1504,16 @@ db_path = "stacks-signer-{signer_id}.sqlite"
container
)
});
self.stacks_signers_containers_ids.push(container.clone());
self.stacks_signers_containers_ids.push(container);

Ok(())
}

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
Expand Down Expand Up @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion components/stacks-network/src/ui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions components/stacks-rpc-client/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading