clippy: Replaces .get(0) with .first() (#34048)

This commit is contained in:
Brooks 2023-11-13 17:22:17 -05:00 committed by GitHub
parent a25eae41fc
commit 725ab37bf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 37 additions and 37 deletions

View File

@ -10937,7 +10937,7 @@ pub mod tests {
expected[0].push(raw_expected[index]);
}
let mut result2 = (0..range).map(|_| Vec::default()).collect::<Vec<_>>();
if let Some(m) = result.get(0) {
if let Some(m) = result.first() {
m.load_all(&mut result2, bin, &PubkeyBinCalculator24::new(bins));
} else {
result2 = vec![];

View File

@ -217,7 +217,7 @@ impl Banks for BanksServer {
.root_bank()
.get_blockhash_last_valid_block_height(blockhash)
.unwrap();
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
let signature = transaction.signatures.first().cloned().unwrap_or_default();
let info = TransactionInfo::new(
signature,
serialize(&transaction).unwrap(),

View File

@ -2104,7 +2104,7 @@ fn check_payer(
}
if !write_messages.is_empty() {
// Assume all write messages cost the same
if let Some(message) = write_messages.get(0) {
if let Some(message) = write_messages.first() {
fee += rpc_client.get_fee_for_message(message)? * (write_messages.len() as u64);
}
}

View File

@ -795,7 +795,7 @@ fn check_payer(
}
if !write_messages.is_empty() {
// Assume all write messages cost the same
if let Some(message) = write_messages.get(0) {
if let Some(message) = write_messages.first() {
fee += rpc_client.get_fee_for_message(message)? * (write_messages.len() as u64);
}
}

View File

@ -2603,8 +2603,8 @@ pub fn process_delegate_stake(
// filter should return at most one result
let rpc_vote_account =
current
.get(0)
.or_else(|| delinquent.get(0))
.first()
.or_else(|| delinquent.first())
.ok_or(CliError::RpcRequestError(format!(
"Vote account not found: {vote_account_pubkey}"
)))?;

View File

@ -1264,7 +1264,7 @@ mod tests {
let commit_transactions_result = commit_transactions_result.unwrap();
assert_eq!(commit_transactions_result.len(), 2);
assert_matches!(
commit_transactions_result.get(0),
commit_transactions_result.first(),
Some(CommitTransactionDetails::Committed { .. })
);
assert_matches!(
@ -1274,7 +1274,7 @@ mod tests {
assert_eq!(retryable_transaction_indexes, vec![1]);
let expected_block_cost = if !apply_cost_tracker_during_replay_enabled {
let actual_bpf_execution_cost = match commit_transactions_result.get(0).unwrap() {
let actual_bpf_execution_cost = match commit_transactions_result.first().unwrap() {
CommitTransactionDetails::Committed { compute_units } => *compute_units,
CommitTransactionDetails::NotCommitted => {
unreachable!()

View File

@ -64,7 +64,7 @@ impl LatestValidatorVotePacket {
let &pubkey = message
.message
.static_account_keys()
.get(0)
.first()
.ok_or(DeserializedPacketError::VoteTransactionError)?;
let slot = vote_state_update_instruction.last_voted_slot().unwrap_or(0);
let timestamp = vote_state_update_instruction.timestamp();

View File

@ -317,7 +317,7 @@ impl TowerStorage for EtcdTowerStorage {
for op_response in response.op_responses() {
if let etcd_client::TxnOpResponse::Get(get_response) = op_response {
if let Some(kv) = get_response.kvs().get(0) {
if let Some(kv) = get_response.kvs().first() {
return bincode::deserialize_from(kv.value())
.map_err(|e| e.into())
.and_then(|t: SavedTowerVersions| t.try_into_tower(node_pubkey));

View File

@ -401,7 +401,7 @@ impl Blockstore {
.into_iter()
.flat_map(|entry| entry.transactions);
for (i, transaction) in transactions.enumerate() {
if let Some(&signature) = transaction.signatures.get(0) {
if let Some(&signature) = transaction.signatures.first() {
batch.delete::<cf::TransactionStatus>((signature, slot))?;
batch.delete::<cf::TransactionMemos>((signature, slot))?;
if !primary_indexes.is_empty() {

View File

@ -984,7 +984,7 @@ mod tests {
(solana_sdk::pubkey::new_rand(), loader_account),
];
let metas = vec![
AccountMeta::new(transaction_accounts.get(0).unwrap().0, false),
AccountMeta::new(transaction_accounts.first().unwrap().0, false),
AccountMeta::new(transaction_accounts.get(1).unwrap().0, false),
AccountMeta::new_readonly(transaction_accounts.get(2).unwrap().0, false),
];

View File

@ -1382,7 +1382,7 @@ mod tests {
.get(&program1)
.expect("Failed to find the entry");
assert_eq!(second_level.len(), 1);
assert!(second_level.get(0).unwrap().is_tombstone());
assert!(second_level.first().unwrap().is_tombstone());
assert_eq!(tombstone.deployment_slot, 10);
assert_eq!(tombstone.effective_slot, 10);
@ -1398,7 +1398,7 @@ mod tests {
.get(&program2)
.expect("Failed to find the entry");
assert_eq!(second_level.len(), 1);
assert!(!second_level.get(0).unwrap().is_tombstone());
assert!(!second_level.first().unwrap().is_tombstone());
let tombstone = set_tombstone(
&mut cache,
@ -1411,7 +1411,7 @@ mod tests {
.get(&program2)
.expect("Failed to find the entry");
assert_eq!(second_level.len(), 2);
assert!(!second_level.get(0).unwrap().is_tombstone());
assert!(!second_level.first().unwrap().is_tombstone());
assert!(second_level.get(1).unwrap().is_tombstone());
assert!(tombstone.is_tombstone());
assert_eq!(tombstone.deployment_slot, 60);

View File

@ -2687,7 +2687,7 @@ mod tests {
&elf_orig,
&elf_new,
);
*instruction_accounts.get_mut(3).unwrap() = instruction_accounts.get(0).unwrap().clone();
*instruction_accounts.get_mut(3).unwrap() = instruction_accounts.first().unwrap().clone();
process_instruction(
transaction_accounts,
instruction_accounts,

View File

@ -1644,7 +1644,7 @@ declare_builtin_function!(
invoke_context.get_check_aligned(),
invoke_context.get_check_size(),
)?
.get(0)
.first()
.ok_or(SyscallError::InvalidLength)?;
if params.base_len > 512 || params.exponent_len > 512 || params.modulus_len > 512 {

View File

@ -124,7 +124,7 @@ impl Locator {
let host = uri.host().map(|h| h.to_string());
match (scheme, host) {
(Some(scheme), Some(host)) if scheme == "usb" => {
let path = uri.path().segments().get(0).and_then(|s| {
let path = uri.path().segments().first().and_then(|s| {
if !s.is_empty() {
Some(s.as_str())
} else {

View File

@ -40,7 +40,7 @@ async fn test_tpu_send_transaction() {
.get_signature_statuses(&signatures)
.await
.unwrap();
if statuses.value.get(0).is_some() {
if statuses.value.first().is_some() {
break;
}
}

View File

@ -496,7 +496,7 @@ fn run_tpu_send_transaction(tpu_use_quic: bool) {
loop {
assert!(now.elapsed() < timeout);
let statuses = rpc_client.get_signature_statuses(&signatures).unwrap();
if statuses.value.get(0).is_some() {
if statuses.value.first().is_some() {
return;
}
}

View File

@ -6384,7 +6384,7 @@ impl Bank {
pub fn process_transaction(&self, tx: &Transaction) -> Result<()> {
self.try_process_transactions(std::iter::once(tx))?[0].clone()?;
tx.signatures
.get(0)
.first()
.map_or(Ok(()), |sig| self.get_signature_status(sig).unwrap())
}

View File

@ -44,7 +44,7 @@ impl AsyncClient for BankClient {
&self,
transaction: VersionedTransaction,
) -> Result<Signature> {
let signature = transaction.signatures.get(0).cloned().unwrap_or_default();
let signature = transaction.signatures.first().cloned().unwrap_or_default();
let transaction_sender = self.transaction_sender.lock().unwrap();
transaction_sender.send(transaction).unwrap();
Ok(signature)
@ -60,7 +60,7 @@ impl SyncClient for BankClient {
let blockhash = self.bank.last_blockhash();
let transaction = Transaction::new(keypairs, message, blockhash);
self.bank.process_transaction(&transaction)?;
Ok(transaction.signatures.get(0).cloned().unwrap_or_default())
Ok(transaction.signatures.first().cloned().unwrap_or_default())
}
/// Create and process a transaction from a single instruction.

View File

@ -16,7 +16,7 @@ fn main() {
s.replace("--bpf", "--sbf")
})
.collect::<Vec<_>>();
let program = if let Some(arg0) = args.get(0) {
let program = if let Some(arg0) = args.first() {
let arg0 = arg0.replace("build-bpf", "build-sbf");
args.remove(0);
PathBuf::from(arg0)
@ -25,7 +25,7 @@ fn main() {
};
// When run as a cargo subcommand, the first program argument is the subcommand name.
// Remove it
if let Some(arg0) = args.get(0) {
if let Some(arg0) = args.first() {
if arg0 == "build-bpf" {
args.remove(0);
}

View File

@ -16,7 +16,7 @@ fn main() {
let cargo_build_sbf = cargo_build_bpf.replace("build-bpf", "build-sbf");
env::set_var("CARGO_BUILD_SBF", cargo_build_sbf);
}
let program = if let Some(arg0) = args.get(0) {
let program = if let Some(arg0) = args.first() {
let cargo_test_sbf = arg0.replace("test-bpf", "test-sbf");
let cargo_build_sbf = cargo_test_sbf.replace("test-sbf", "build-sbf");
env::set_var("CARGO_BUILD_SBF", cargo_build_sbf);
@ -27,7 +27,7 @@ fn main() {
};
// When run as a cargo subcommand, the first program argument is the subcommand name.
// Remove it
if let Some(arg0) = args.get(0) {
if let Some(arg0) = args.first() {
if arg0 == "test-bpf" {
args.remove(0);
}

View File

@ -580,7 +580,7 @@ mod test {
// Slot 2 interrupted slot 1
let shreds = run.finish_prev_slot(&keypair, 0, &mut ProcessShredsStats::default());
let shred = shreds
.get(0)
.first()
.expect("Expected a shred that signals an interrupt");
// Validate the shred

View File

@ -244,7 +244,7 @@ fn wait_for_restart_window(
Err("Current epoch is almost complete".to_string())
} else {
while leader_schedule
.get(0)
.front()
.map(|slot| *slot < epoch_info.absolute_slot)
.unwrap_or(false)
{
@ -258,7 +258,7 @@ fn wait_for_restart_window(
upcoming_idle_windows.pop();
}
match leader_schedule.get(0) {
match leader_schedule.front() {
None => {
Ok(()) // Validator has no leader slots
}

View File

@ -23,7 +23,7 @@ pub fn parse_sanitized_vote_transaction(tx: &SanitizedTransaction) -> Option<Par
let first_account = usize::from(*first_instruction.accounts.first()?);
let key = message.account_keys().get(first_account)?;
let (vote, switch_proof_hash) = parse_vote_instruction_data(&first_instruction.data)?;
let signature = tx.signatures().get(0).cloned().unwrap_or_default();
let signature = tx.signatures().first().cloned().unwrap_or_default();
Some((*key, vote, switch_proof_hash, signature))
}
@ -40,7 +40,7 @@ pub fn parse_vote_transaction(tx: &Transaction) -> Option<ParsedVote> {
let first_account = usize::from(*first_instruction.accounts.first()?);
let key = message.account_keys.get(first_account)?;
let (vote, switch_proof_hash) = parse_vote_instruction_data(&first_instruction.data)?;
let signature = tx.signatures.get(0).cloned().unwrap_or_default();
let signature = tx.signatures.first().cloned().unwrap_or_default();
Some((*key, vote, switch_proof_hash, signature))
}

View File

@ -116,10 +116,10 @@ impl ZkProofData<BatchedGroupedCiphertext2HandlesValidityProofContext>
let grouped_ciphertext_hi: GroupedElGamalCiphertext<2> =
self.context.grouped_ciphertext_hi.try_into()?;
let destination_handle_lo = grouped_ciphertext_lo.handles.get(0).unwrap();
let destination_handle_lo = grouped_ciphertext_lo.handles.first().unwrap();
let auditor_handle_lo = grouped_ciphertext_lo.handles.get(1).unwrap();
let destination_handle_hi = grouped_ciphertext_hi.handles.get(0).unwrap();
let destination_handle_hi = grouped_ciphertext_hi.handles.first().unwrap();
let auditor_handle_hi = grouped_ciphertext_hi.handles.get(1).unwrap();
let proof: BatchedGroupedCiphertext2HandlesValidityProof = self.proof.try_into()?;

View File

@ -105,7 +105,7 @@ impl ZkProofData<GroupedCiphertext2HandlesValidityProofContext>
let grouped_ciphertext: GroupedElGamalCiphertext<2> =
self.context.grouped_ciphertext.try_into()?;
let destination_handle = grouped_ciphertext.handles.get(0).unwrap();
let destination_handle = grouped_ciphertext.handles.first().unwrap();
let auditor_handle = grouped_ciphertext.handles.get(1).unwrap();
let proof: GroupedCiphertext2HandlesValidityProof = self.proof.try_into()?;

View File

@ -35,7 +35,7 @@ impl TransferAmountCiphertext {
pub fn get_source_handle(&self) -> &DecryptHandle {
// `TransferAmountCiphertext` is a wrapper for `GroupedElGamalCiphertext<3>`, which
// holds exactly three decryption handles.
self.0.handles.get(0).unwrap()
self.0.handles.first().unwrap()
}
pub fn get_destination_handle(&self) -> &DecryptHandle {
@ -80,7 +80,7 @@ impl FeeEncryption {
pub fn get_destination_handle(&self) -> &DecryptHandle {
// `FeeEncryption` is a wrapper for `GroupedElGamalCiphertext<2>`, which holds
// exactly two decryption handles.
self.0.handles.get(0).unwrap()
self.0.handles.first().unwrap()
}
pub fn get_withdraw_withheld_authority_handle(&self) -> &DecryptHandle {