fixes errors from clippy::redundant_clone (#29536)

https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
This commit is contained in:
behzad nouri 2023-01-05 18:42:19 +00:00 committed by GitHub
parent 3b7ebfe50e
commit 12da2da389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 107 deletions

View File

@ -87,8 +87,7 @@ mod test {
meta: lookup_table_meta, meta: lookup_table_meta,
addresses: Cow::Owned(addresses), addresses: Cow::Owned(addresses),
}; };
let lookup_table_data = let lookup_table_data = AddressLookupTable::serialize_for_tests(lookup_table).unwrap();
AddressLookupTable::serialize_for_tests(lookup_table.clone()).unwrap();
let parsing_result = parse_address_lookup_table(&lookup_table_data).unwrap(); let parsing_result = parse_address_lookup_table(&lookup_table_data).unwrap();
if let LookupTableAccountType::LookupTable(ui_lookup_table) = parsing_result { if let LookupTableAccountType::LookupTable(ui_lookup_table) = parsing_result {

View File

@ -224,16 +224,13 @@ mod tests {
#[test] #[test]
fn test_values_of() { fn test_values_of() {
let matches = let matches = app().get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
app()
.clone()
.get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
assert_eq!(values_of(&matches, "multiple"), Some(vec![50, 39])); assert_eq!(values_of(&matches, "multiple"), Some(vec![50, 39]));
assert_eq!(values_of::<u64>(&matches, "single"), None); assert_eq!(values_of::<u64>(&matches, "single"), None);
let pubkey0 = solana_sdk::pubkey::new_rand(); let pubkey0 = solana_sdk::pubkey::new_rand();
let pubkey1 = 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", "test",
"--multiple", "--multiple",
&pubkey0.to_string(), &pubkey0.to_string(),
@ -248,16 +245,12 @@ mod tests {
#[test] #[test]
fn test_value_of() { fn test_value_of() {
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "50"]);
.clone()
.get_matches_from(vec!["test", "--single", "50"]);
assert_eq!(value_of(&matches, "single"), Some(50)); assert_eq!(value_of(&matches, "single"), Some(50));
assert_eq!(value_of::<u64>(&matches, "multiple"), None); assert_eq!(value_of::<u64>(&matches, "multiple"), None);
let pubkey = solana_sdk::pubkey::new_rand(); let pubkey = solana_sdk::pubkey::new_rand();
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
.clone()
.get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
assert_eq!(value_of(&matches, "single"), Some(pubkey)); assert_eq!(value_of(&matches, "single"), Some(pubkey));
} }
@ -267,19 +260,14 @@ mod tests {
let outfile = tmp_file_path("test_keypair_of.json", &keypair.pubkey()); let outfile = tmp_file_path("test_keypair_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap(); let _ = write_keypair_file(&keypair, &outfile).unwrap();
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!( assert_eq!(
keypair_of(&matches, "single").unwrap().pubkey(), keypair_of(&matches, "single").unwrap().pubkey(),
keypair.pubkey() keypair.pubkey()
); );
assert!(keypair_of(&matches, "multiple").is_none()); assert!(keypair_of(&matches, "multiple").is_none());
let matches = let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert!(keypair_of(&matches, "single").is_none()); assert!(keypair_of(&matches, "single").is_none());
fs::remove_file(&outfile).unwrap(); fs::remove_file(&outfile).unwrap();
@ -291,22 +279,15 @@ mod tests {
let outfile = tmp_file_path("test_pubkey_of.json", &keypair.pubkey()); let outfile = tmp_file_path("test_pubkey_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap(); let _ = write_keypair_file(&keypair, &outfile).unwrap();
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey())); assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));
assert_eq!(pubkey_of(&matches, "multiple"), None); assert_eq!(pubkey_of(&matches, "multiple"), None);
let matches = let matches =
app() app().get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
.clone()
.get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey())); assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));
let matches = let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert_eq!(pubkey_of(&matches, "single"), None); assert_eq!(pubkey_of(&matches, "single"), None);
fs::remove_file(&outfile).unwrap(); fs::remove_file(&outfile).unwrap();
@ -318,7 +299,7 @@ mod tests {
let outfile = tmp_file_path("test_pubkeys_of.json", &keypair.pubkey()); let outfile = tmp_file_path("test_pubkeys_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap(); let _ = write_keypair_file(&keypair, &outfile).unwrap();
let matches = app().clone().get_matches_from(vec![ let matches = app().get_matches_from(vec![
"test", "test",
"--multiple", "--multiple",
&keypair.pubkey().to_string(), &keypair.pubkey().to_string(),
@ -340,13 +321,8 @@ mod tests {
let sig2 = Keypair::new().sign_message(&[1u8]); let sig2 = Keypair::new().sign_message(&[1u8]);
let signer1 = format!("{key1}={sig1}"); let signer1 = format!("{key1}={sig1}");
let signer2 = format!("{key2}={sig2}"); let signer2 = format!("{key2}={sig2}");
let matches = app().clone().get_matches_from(vec![ let matches =
"test", app().get_matches_from(vec!["test", "--multiple", &signer1, "--multiple", &signer2]);
"--multiple",
&signer1,
"--multiple",
&signer2,
]);
assert_eq!( assert_eq!(
pubkeys_sigs_of(&matches, "multiple"), pubkeys_sigs_of(&matches, "multiple"),
Some(vec![(key1, sig1), (key2, sig2)]) Some(vec![(key1, sig1), (key2, sig2)])
@ -355,19 +331,13 @@ mod tests {
#[test] #[test]
fn test_lamports_of_sol() { fn test_lamports_of_sol() {
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "50"]);
.clone()
.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, "single"), Some(50_000_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None); assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "1.5"]);
.clone()
.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, "single"), Some(1_500_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None); assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "0.03"]);
.clone()
.get_matches_from(vec!["test", "--single", "0.03"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(30_000_000)); assert_eq!(lamports_of_sol(&matches, "single"), Some(30_000_000));
} }
} }

View File

@ -225,16 +225,13 @@ mod tests {
#[test] #[test]
fn test_values_of() { fn test_values_of() {
let matches = let matches = app().get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
app()
.clone()
.get_matches_from(vec!["test", "--multiple", "50", "--multiple", "39"]);
assert_eq!(values_of(&matches, "multiple"), Some(vec![50, 39])); assert_eq!(values_of(&matches, "multiple"), Some(vec![50, 39]));
assert_eq!(values_of::<u64>(&matches, "single"), None); assert_eq!(values_of::<u64>(&matches, "single"), None);
let pubkey0 = solana_sdk::pubkey::new_rand(); let pubkey0 = solana_sdk::pubkey::new_rand();
let pubkey1 = 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", "test",
"--multiple", "--multiple",
&pubkey0.to_string(), &pubkey0.to_string(),
@ -249,16 +246,12 @@ mod tests {
#[test] #[test]
fn test_value_of() { fn test_value_of() {
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "50"]);
.clone()
.get_matches_from(vec!["test", "--single", "50"]);
assert_eq!(value_of(&matches, "single"), Some(50)); assert_eq!(value_of(&matches, "single"), Some(50));
assert_eq!(value_of::<u64>(&matches, "multiple"), None); assert_eq!(value_of::<u64>(&matches, "multiple"), None);
let pubkey = solana_sdk::pubkey::new_rand(); let pubkey = solana_sdk::pubkey::new_rand();
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
.clone()
.get_matches_from(vec!["test", "--single", &pubkey.to_string()]);
assert_eq!(value_of(&matches, "single"), Some(pubkey)); assert_eq!(value_of(&matches, "single"), Some(pubkey));
} }
@ -268,19 +261,14 @@ mod tests {
let outfile = tmp_file_path("test_keypair_of.json", &keypair.pubkey()); let outfile = tmp_file_path("test_keypair_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap(); let _ = write_keypair_file(&keypair, &outfile).unwrap();
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!( assert_eq!(
keypair_of(&matches, "single").unwrap().pubkey(), keypair_of(&matches, "single").unwrap().pubkey(),
keypair.pubkey() keypair.pubkey()
); );
assert!(keypair_of(&matches, "multiple").is_none()); assert!(keypair_of(&matches, "multiple").is_none());
let matches = let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert!(keypair_of(&matches, "single").is_none()); assert!(keypair_of(&matches, "single").is_none());
fs::remove_file(&outfile).unwrap(); fs::remove_file(&outfile).unwrap();
@ -292,22 +280,15 @@ mod tests {
let outfile = tmp_file_path("test_pubkey_of.json", &keypair.pubkey()); let outfile = tmp_file_path("test_pubkey_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap(); let _ = write_keypair_file(&keypair, &outfile).unwrap();
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", &outfile]);
.clone()
.get_matches_from(vec!["test", "--single", &outfile]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey())); assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));
assert_eq!(pubkey_of(&matches, "multiple"), None); assert_eq!(pubkey_of(&matches, "multiple"), None);
let matches = let matches =
app() app().get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
.clone()
.get_matches_from(vec!["test", "--single", &keypair.pubkey().to_string()]);
assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey())); assert_eq!(pubkey_of(&matches, "single"), Some(keypair.pubkey()));
let matches = let matches = app().get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
app()
.clone()
.get_matches_from(vec!["test", "--single", "random_keypair_file.json"]);
assert_eq!(pubkey_of(&matches, "single"), None); assert_eq!(pubkey_of(&matches, "single"), None);
fs::remove_file(&outfile).unwrap(); fs::remove_file(&outfile).unwrap();
@ -319,7 +300,7 @@ mod tests {
let outfile = tmp_file_path("test_pubkeys_of.json", &keypair.pubkey()); let outfile = tmp_file_path("test_pubkeys_of.json", &keypair.pubkey());
let _ = write_keypair_file(&keypair, &outfile).unwrap(); let _ = write_keypair_file(&keypair, &outfile).unwrap();
let matches = app().clone().get_matches_from(vec![ let matches = app().get_matches_from(vec![
"test", "test",
"--multiple", "--multiple",
&keypair.pubkey().to_string(), &keypair.pubkey().to_string(),
@ -341,13 +322,8 @@ mod tests {
let sig2 = Keypair::new().sign_message(&[1u8]); let sig2 = Keypair::new().sign_message(&[1u8]);
let signer1 = format!("{key1}={sig1}"); let signer1 = format!("{key1}={sig1}");
let signer2 = format!("{key2}={sig2}"); let signer2 = format!("{key2}={sig2}");
let matches = app().clone().get_matches_from(vec![ let matches =
"test", app().get_matches_from(vec!["test", "--multiple", &signer1, "--multiple", &signer2]);
"--multiple",
&signer1,
"--multiple",
&signer2,
]);
assert_eq!( assert_eq!(
pubkeys_sigs_of(&matches, "multiple"), pubkeys_sigs_of(&matches, "multiple"),
Some(vec![(key1, sig1), (key2, sig2)]) Some(vec![(key1, sig1), (key2, sig2)])
@ -356,19 +332,13 @@ mod tests {
#[test] #[test]
fn test_lamports_of_sol() { fn test_lamports_of_sol() {
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "50"]);
.clone()
.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, "single"), Some(50_000_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None); assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "1.5"]);
.clone()
.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, "single"), Some(1_500_000_000));
assert_eq!(lamports_of_sol(&matches, "multiple"), None); assert_eq!(lamports_of_sol(&matches, "multiple"), None);
let matches = app() let matches = app().get_matches_from(vec!["test", "--single", "0.03"]);
.clone()
.get_matches_from(vec!["test", "--single", "0.03"]);
assert_eq!(lamports_of_sol(&matches, "single"), Some(30_000_000)); assert_eq!(lamports_of_sol(&matches, "single"), Some(30_000_000));
} }
} }

View File

@ -1788,7 +1788,7 @@ fn initialize_rpc_transaction_history_services(
transaction_status_receiver, transaction_status_receiver,
max_complete_transaction_status_slot.clone(), max_complete_transaction_status_slot.clone(),
enable_rpc_transaction_history, enable_rpc_transaction_history,
transaction_notifier.clone(), transaction_notifier,
blockstore.clone(), blockstore.clone(),
enable_extended_tx_metadata_storage, enable_extended_tx_metadata_storage,
exit, exit,

View File

@ -7339,7 +7339,7 @@ mod tests {
&stake_account, &stake_account,
&authorized_staker, &authorized_staker,
&new_vote_address, &new_vote_address,
&uninitialized_stake_account.clone(), // <-- Invalid vote account &uninitialized_stake_account, // <-- Invalid vote account
&uninitialized_stake_address, &uninitialized_stake_address,
&uninitialized_stake_account, &uninitialized_stake_account,
Err(InstructionError::IncorrectProgramId), Err(InstructionError::IncorrectProgramId),
@ -7350,7 +7350,7 @@ mod tests {
// //
let _ = process_instruction_redelegate( let _ = process_instruction_redelegate(
&stake_address, &stake_address,
&uninitialized_stake_account.clone(), // <-- Uninitialized stake account &uninitialized_stake_account, // <-- Uninitialized stake account
&authorized_staker, &authorized_staker,
&new_vote_address, &new_vote_address,
&new_vote_account, &new_vote_account,

View File

@ -327,9 +327,7 @@ mod tests {
// are broken, so unset the requires() to recreate that condition // are broken, so unset the requires() to recreate that condition
.arg(sign_only_arg().requires("")); .arg(sign_only_arg().requires(""));
let matches = test_commands let matches = test_commands.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
.clone()
.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
BlockhashQuery::new_from_matches(&matches); BlockhashQuery::new_from_matches(&matches);
} }
@ -344,7 +342,7 @@ mod tests {
let nonce_pubkey = Pubkey::new(&[1u8; 32]); let nonce_pubkey = Pubkey::new(&[1u8; 32]);
let nonce_string = nonce_pubkey.to_string(); 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", "blockhash_query_test",
"--sign-only", "--sign-only",
"--nonce", "--nonce",

View File

@ -259,9 +259,7 @@ mod tests {
// are broken, so unset the requires() to recreate that condition // are broken, so unset the requires() to recreate that condition
.arg(sign_only_arg().requires("")); .arg(sign_only_arg().requires(""));
let matches = test_commands let matches = test_commands.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
.clone()
.get_matches_from(vec!["blockhash_query_test", "--sign-only"]);
BlockhashQuery::new_from_matches(&matches); BlockhashQuery::new_from_matches(&matches);
} }
@ -276,7 +274,7 @@ mod tests {
let nonce_pubkey = Pubkey::new(&[1u8; 32]); let nonce_pubkey = Pubkey::new(&[1u8; 32]);
let nonce_string = nonce_pubkey.to_string(); 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", "blockhash_query_test",
"--sign-only", "--sign-only",
"--nonce", "--nonce",

View File

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

View File

@ -278,7 +278,6 @@ impl RangeProof {
let gs = s.iter().map(|s_i| minus_z - a * s_i); let gs = s.iter().map(|s_i| minus_z - a * s_i);
let hs = s_inv let hs = s_inv
.clone()
.zip(util::exp_iter(y.invert())) .zip(util::exp_iter(y.invert()))
.zip(concat_z_and_2.iter()) .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)); .map(|((s_i_inv, exp_y_inv), z_and_2)| z + exp_y_inv * (zz * z_and_2 - b * s_i_inv));