Skip to content

Commit

Permalink
fixes errors from clippy::redundant_clone (solana-labs#29536)
Browse files Browse the repository at this point in the history
  • Loading branch information
behzadnouri authored and gnapoli23 committed Jan 10, 2023
1 parent 30d33fd commit af07aae
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 107 deletions.
3 changes: 1 addition & 2 deletions account-decoder/src/parse_address_lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ mod test {
meta: lookup_table_meta,
addresses: Cow::Owned(addresses),
};
let lookup_table_data =
AddressLookupTable::serialize_for_tests(lookup_table.clone()).unwrap();
let lookup_table_data = AddressLookupTable::serialize_for_tests(lookup_table).unwrap();

let parsing_result = parse_address_lookup_table(&lookup_table_data).unwrap();
if let LookupTableAccountType::LookupTable(ui_lookup_table) = parsing_result {
Expand Down
60 changes: 15 additions & 45 deletions clap-utils/src/input_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,13 @@ mod tests {

#[test]
fn test_values_of() {
let matches =
app()
.clone()
.get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
let matches = app().get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
assert_eq!(values_of(&matches, "multiple"), Some(vec![50, 39]));
assert_eq!(values_of::<u64>(&matches, "single"), None);

let pubkey0 = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_sdk::pubkey::new_rand();
let matches = app().clone().get_matches_from(vec![
let matches = app().get_matches_from(vec![
"test",
"--multiple",
&pubkey0.to_string(),
Expand All @@ -248,16 +245,12 @@ mod tests {

#[test]
fn test_value_of() {
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "50"]);
let matches = app().get_matches_from(vec!["test", "--single", "50"]);
assert_eq!(value_of(&matches, "single"), Some(50));
assert_eq!(value_of::<u64>(&matches, "multiple"), None);

let pubkey = solana_sdk::pubkey::new_rand();
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
let matches = app().get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
assert_eq!(value_of(&matches, "single"), Some(pubkey));
}

Expand All @@ -267,19 +260,14 @@ mod tests {
let outfile = tmp_file_path("test_keypair_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap();

let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!(
keypair_of(&matches, "single").unwrap().pubkey(),
keypair.pubkey()
);
assert!(keypair_of(&matches, "multiple").is_none());

let matches =
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert!(keypair_of(&matches, "single").is_none());

fs::remove_file(&outfile).unwrap();
Expand All @@ -291,22 +279,15 @@ mod tests {
let outfile = tmp_file_path("test_pubkey_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap();

let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));
assert_eq!(pubkey_of(&matches, "multiple"), None);

let matches =
app()
.clone()
.get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
app().get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));

let matches =
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert_eq!(pubkey_of(&matches, "single"), None);

fs::remove_file(&outfile).unwrap();
Expand All @@ -318,7 +299,7 @@ mod tests {
let outfile = tmp_file_path("test_pubkeys_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap();

let matches = app().clone().get_matches_from(vec![
let matches = app().get_matches_from(vec![
"test",
"--multiple",
&keypair.pubkey().to_string(),
Expand All @@ -340,13 +321,8 @@ mod tests {
let sig2 = Keypair::new().sign_message(&[1u8]);
let signer1 = format!("{key1}={sig1}");
let signer2 = format!("{key2}={sig2}");
let matches = app().clone().get_matches_from(vec![
"test",
"--multiple",
&signer1,
"--multiple",
&signer2,
]);
let matches =
app().get_matches_from(vec!["test", "--multiple", &signer1, "--multiple", &signer2]);
assert_eq!(
pubkeys_sigs_of(&matches, "multiple"),
Some(vec![(key1, sig1), (key2, sig2)])
Expand All @@ -355,19 +331,13 @@ mod tests {

#[test]
fn test_lamports_of_sol() {
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "50"]);
let matches = app().get_matches_from(vec!["test", "--single", "50"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(50_000_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "1.5"]);
let matches = app().get_matches_from(vec!["test", "--single", "1.5"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(1_500_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "0.03"]);
let matches = app().get_matches_from(vec!["test", "--single", "0.03"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(30_000_000));
}
}
60 changes: 15 additions & 45 deletions clap-v3-utils/src/input_parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,13 @@ mod tests {

#[test]
fn test_values_of() {
let matches =
app()
.clone()
.get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
let matches = app().get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
assert_eq!(values_of(&matches, "multiple"), Some(vec![50, 39]));
assert_eq!(values_of::<u64>(&matches, "single"), None);

let pubkey0 = solana_sdk::pubkey::new_rand();
let pubkey1 = solana_sdk::pubkey::new_rand();
let matches = app().clone().get_matches_from(vec![
let matches = app().get_matches_from(vec![
"test",
"--multiple",
&pubkey0.to_string(),
Expand All @@ -249,16 +246,12 @@ mod tests {

#[test]
fn test_value_of() {
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "50"]);
let matches = app().get_matches_from(vec!["test", "--single", "50"]);
assert_eq!(value_of(&matches, "single"), Some(50));
assert_eq!(value_of::<u64>(&matches, "multiple"), None);

let pubkey = solana_sdk::pubkey::new_rand();
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
let matches = app().get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
assert_eq!(value_of(&matches, "single"), Some(pubkey));
}

Expand All @@ -268,19 +261,14 @@ mod tests {
let outfile = tmp_file_path("test_keypair_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap();

let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!(
keypair_of(&matches, "single").unwrap().pubkey(),
keypair.pubkey()
);
assert!(keypair_of(&matches, "multiple").is_none());

let matches =
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert!(keypair_of(&matches, "single").is_none());

fs::remove_file(&outfile).unwrap();
Expand All @@ -292,22 +280,15 @@ mod tests {
let outfile = tmp_file_path("test_pubkey_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap();

let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));
assert_eq!(pubkey_of(&matches, "multiple"), None);

let matches =
app()
.clone()
.get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
app().get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));

let matches =
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert_eq!(pubkey_of(&matches, "single"), None);

fs::remove_file(&outfile).unwrap();
Expand All @@ -319,7 +300,7 @@ mod tests {
let outfile = tmp_file_path("test_pubkeys_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap();

let matches = app().clone().get_matches_from(vec![
let matches = app().get_matches_from(vec![
"test",
"--multiple",
&keypair.pubkey().to_string(),
Expand All @@ -341,13 +322,8 @@ mod tests {
let sig2 = Keypair::new().sign_message(&[1u8]);
let signer1 = format!("{key1}={sig1}");
let signer2 = format!("{key2}={sig2}");
let matches = app().clone().get_matches_from(vec![
"test",
"--multiple",
&signer1,
"--multiple",
&signer2,
]);
let matches =
app().get_matches_from(vec!["test", "--multiple", &signer1, "--multiple", &signer2]);
assert_eq!(
pubkeys_sigs_of(&matches, "multiple"),
Some(vec![(key1, sig1), (key2, sig2)])
Expand All @@ -356,19 +332,13 @@ mod tests {

#[test]
fn test_lamports_of_sol() {
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "50"]);
let matches = app().get_matches_from(vec!["test", "--single", "50"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(50_000_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "1.5"]);
let matches = app().get_matches_from(vec!["test", "--single", "1.5"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(1_500_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app()
.clone()
.get_matches_from(vec!["test", "--single", "0.03"]);
let matches = app().get_matches_from(vec!["test", "--single", "0.03"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(30_000_000));
}
}
2 changes: 1 addition & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,7 @@ fn initialize_rpc_transaction_history_services(
transaction_status_receiver,
max_complete_transaction_status_slot.clone(),
enable_rpc_transaction_history,
transaction_notifier.clone(),
transaction_notifier,
blockstore.clone(),
enable_extended_tx_metadata_storage,
exit,
Expand Down
4 changes: 2 additions & 2 deletions programs/stake/src/stake_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7339,7 +7339,7 @@ mod tests {
&stake_account,
&authorized_staker,
&new_vote_address,
&uninitialized_stake_account.clone(), // <-- Invalid vote account
&uninitialized_stake_account, // <-- Invalid vote account
&uninitialized_stake_address,
&uninitialized_stake_account,
Err(InstructionError::IncorrectProgramId),
Expand All @@ -7350,7 +7350,7 @@ mod tests {
//
let _ = process_instruction_redelegate(
&stake_address,
&uninitialized_stake_account.clone(), // <-- Uninitialized stake account
&uninitialized_stake_account, // <-- Uninitialized stake account
&authorized_staker,
&new_vote_address,
&new_vote_account,
Expand Down
6 changes: 2 additions & 4 deletions rpc-client-nonce-utils/src/blockhash_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,7 @@ mod tests {
// are broken, so unset the requires() to recreate that condition
.arg(sign_only_arg().requires(""));

let matches = test_commands
.clone()
.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
let matches = test_commands.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
BlockhashQuery::new_from_matches(&matches);
}

Expand All @@ -344,7 +342,7 @@ mod tests {
let nonce_pubkey = Pubkey::new(&[1u8; 32]);
let nonce_string = nonce_pubkey.to_string();

let matches = test_commands.clone().get_matches_from(vec![
let matches = test_commands.get_matches_from(vec![
"blockhash_query_test",
"--sign-only",
"--nonce",
Expand Down
6 changes: 2 additions & 4 deletions rpc-client-nonce-utils/src/nonblocking/blockhash_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,7 @@ mod tests {
// are broken, so unset the requires() to recreate that condition
.arg(sign_only_arg().requires(""));

let matches = test_commands
.clone()
.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
let matches = test_commands.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
BlockhashQuery::new_from_matches(&matches);
}

Expand All @@ -276,7 +274,7 @@ mod tests {
let nonce_pubkey = Pubkey::new(&[1u8; 32]);
let nonce_string = nonce_pubkey.to_string();

let matches = test_commands.clone().get_matches_from(vec![
let matches = test_commands.get_matches_from(vec![
"blockhash_query_test",
"--sign-only",
"--nonce",
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3475,7 +3475,7 @@ mod tests {
Some((&nonce, true)),
&DurableNonce::default(),
1,
&post_fee_payer_account.clone(),
&post_fee_payer_account,
));

assert!(run_prepare_if_nonce_account_test(
Expand All @@ -3486,7 +3486,7 @@ mod tests {
Some((&nonce, true)),
&DurableNonce::default(),
1,
&post_fee_payer_account.clone(),
&post_fee_payer_account,
));

assert!(run_prepare_if_nonce_account_test(
Expand All @@ -3500,7 +3500,7 @@ mod tests {
None,
&DurableNonce::default(),
1,
&post_fee_payer_account.clone(),
&post_fee_payer_account,
));

assert!(run_prepare_if_nonce_account_test(
Expand Down
1 change: 0 additions & 1 deletion zk-token-sdk/src/range_proof/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ impl RangeProof {

let gs = s.iter().map(|s_i| minus_z - a * s_i);
let hs = s_inv
.clone()
.zip(util::exp_iter(y.invert()))
.zip(concat_z_and_2.iter())
.map(|((s_i_inv, exp_y_inv), z_and_2)| z + exp_y_inv * (zz * z_and_2 - b * s_i_inv));
Expand Down

0 comments on commit af07aae

Please sign in to comment.