diff --git a/account-decoder/src/parse_config.rs b/account-decoder/src/parse_config.rs index f070b2fd8360a3..f1fa51a286b6a7 100644 --- a/account-decoder/src/parse_config.rs +++ b/account-decoder/src/parse_config.rs @@ -82,7 +82,7 @@ impl From for UiStakeConfig { } } -#[derive(Debug, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct UiConfig { pub keys: Vec, diff --git a/ci/test-checks.sh b/ci/test-checks.sh index 6ffdf134746bc7..5dcf686de9680d 100755 --- a/ci/test-checks.sh +++ b/ci/test-checks.sh @@ -67,7 +67,9 @@ fi # -Z... is needed because of clippy bug: https://github.com/rust-lang/rust-clippy/issues/4612 # run nightly clippy for `sdk/` as there's a moderate amount of nightly-only code there - _ scripts/cargo-for-all-lock-files.sh -- nightly clippy -Zunstable-options --all-targets -- --deny=warnings --deny=clippy::integer_arithmetic + _ scripts/cargo-for-all-lock-files.sh -- nightly clippy -Zunstable-options --all-targets -- \ + --deny=warnings \ + --deny=clippy::integer_arithmetic \ _ scripts/cargo-for-all-lock-files.sh -- nightly fmt --all -- --check diff --git a/cli/src/cluster_query.rs b/cli/src/cluster_query.rs index e1779717cf7527..0ca373e80cf73c 100644 --- a/cli/src/cluster_query.rs +++ b/cli/src/cluster_query.rs @@ -1125,7 +1125,7 @@ pub fn process_get_epoch_info(rpc_client: &RpcClient, config: &CliConfig) -> Pro let first_block_in_epoch = rpc_client .get_blocks_with_limit(epoch_expected_start_slot, 1) .ok() - .and_then(|slot_vec| slot_vec.get(0).cloned()) + .and_then(|slot_vec| slot_vec.first().cloned()) .unwrap_or(epoch_expected_start_slot); let start_block_time = rpc_client diff --git a/cli/src/program.rs b/cli/src/program.rs index 9cc20e89a95d83..9089ba412ace94 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -1621,12 +1621,12 @@ fn process_close( }) = account.state() { if authority_pubkey != Some(authority_signer.pubkey()) { - return Err(format!( + Err(format!( "Program authority {:?} does not match {:?}", authority_pubkey, Some(authority_signer.pubkey()) ) - .into()); + .into()) } else { close( rpc_client, @@ -1645,22 +1645,16 @@ fn process_close( )) } } else { - return Err( - format!("Program {} has been closed", account_pubkey).into() - ); + Err(format!("Program {} has been closed", account_pubkey).into()) } } else { - return Err(format!("Program {} has been closed", account_pubkey).into()); + Err(format!("Program {} has been closed", account_pubkey).into()) } } - _ => { - return Err( - format!("{} is not a Program or Buffer account", account_pubkey).into(), - ); - } + _ => Err(format!("{} is not a Program or Buffer account", account_pubkey).into()), } } else { - return Err(format!("Unable to find the account {}", account_pubkey).into()); + Err(format!("Unable to find the account {}", account_pubkey).into()) } } else { let buffers = get_buffers( diff --git a/client/src/rpc_config.rs b/client/src/rpc_config.rs index 8bab4f679e3df1..d5bc986a21cf6e 100644 --- a/client/src/rpc_config.rs +++ b/client/src/rpc_config.rs @@ -215,7 +215,7 @@ pub struct RpcSignaturesForAddressConfig { pub min_context_slot: Option, } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[serde(untagged)] pub enum RpcEncodingConfigWrapper { Deprecated(Option), diff --git a/client/src/rpc_response.rs b/client/src/rpc_response.rs index 9957838b2e3095..b54feb3a777139 100644 --- a/client/src/rpc_response.rs +++ b/client/src/rpc_response.rs @@ -73,13 +73,13 @@ impl RpcResponseContext { } } -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Response { pub context: RpcResponseContext, pub value: T, } -#[derive(Debug, PartialEq, Serialize, Deserialize)] +#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct RpcBlockCommitment { pub commitment: Option, diff --git a/core/src/consensus.rs b/core/src/consensus.rs index 295d0163d82756..300d61d81bffb2 100644 --- a/core/src/consensus.rs +++ b/core/src/consensus.rs @@ -439,8 +439,8 @@ impl Tower { pub fn last_voted_slot_in_bank(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option { let (_stake, vote_account) = bank.get_vote_account(vote_account_pubkey)?; - let slot = vote_account.vote_state().as_ref().ok()?.last_voted_slot(); - slot + let vote_state = vote_account.vote_state(); + vote_state.as_ref().ok()?.last_voted_slot() } pub fn record_bank_vote(&mut self, bank: &Bank, vote_account_pubkey: &Pubkey) -> Option { diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 9335b75bfbbade..30c1f356ea10cd 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -2881,7 +2881,7 @@ impl ReplayStage { let exists = leader_propagated_stats .propagated_node_ids .contains(node_pubkey); - leader_propagated_stats.add_node_pubkey(&*node_pubkey, leader_bank); + leader_propagated_stats.add_node_pubkey(node_pubkey, leader_bank); !exists }); diff --git a/ledger/src/blockstore.rs b/ledger/src/blockstore.rs index 62ef2db81c1725..d8f8e513f758ab 100644 --- a/ledger/src/blockstore.rs +++ b/ledger/src/blockstore.rs @@ -3536,7 +3536,7 @@ fn handle_chaining( // Write all the newly changed slots in new_chained_slots to the write_batch for (slot, meta) in new_chained_slots.iter() { - let meta: &SlotMeta = &RefCell::borrow(&*meta); + let meta: &SlotMeta = &RefCell::borrow(meta); write_batch.put::(*slot, meta)?; } Ok(()) @@ -3625,8 +3625,8 @@ fn handle_chaining_for_slot( // update all child slots with `is_connected` = true because these children are also now newly // connected to trunk of the ledger let should_propagate_is_connected = - is_newly_completed_slot(&RefCell::borrow(&*meta), meta_backup) - && RefCell::borrow(&*meta).is_connected; + is_newly_completed_slot(&RefCell::borrow(meta), meta_backup) + && RefCell::borrow(meta).is_connected; if should_propagate_is_connected { // slot_function returns a boolean indicating whether to explore the children diff --git a/ledger/src/shred/legacy.rs b/ledger/src/shred/legacy.rs index 4ec27ca9533e0f..86bbf6b9764368 100644 --- a/ledger/src/shred/legacy.rs +++ b/ledger/src/shred/legacy.rs @@ -183,6 +183,7 @@ impl ShredDataTrait for ShredData { fn data(&self) -> Result<&[u8], Error> { let size = usize::from(self.data_header.size); + #[allow(clippy::manual_range_contains)] if size > self.payload.len() || size < SIZE_OF_DATA_SHRED_HEADERS || size > SIZE_OF_DATA_SHRED_HEADERS + Self::CAPACITY diff --git a/perf/benches/shrink.rs b/perf/benches/shrink.rs index 5de33533ec646c..e813a530359423 100644 --- a/perf/benches/shrink.rs +++ b/perf/benches/shrink.rs @@ -24,7 +24,7 @@ fn test_packet_with_size(size: usize, rng: &mut ThreadRng) -> Vec { fn do_bench_shrink_packets(bencher: &mut Bencher, mut batches: Vec) { // verify packets bencher.iter(|| { - let _ans = sigverify::shrink_batches(&mut batches); + sigverify::shrink_batches(&mut batches); batches.iter_mut().for_each(|b| { b.iter_mut() .for_each(|p| p.meta.set_discard(thread_rng().gen())) diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index 759d535ac36095..50e508762dfd4f 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -1439,7 +1439,7 @@ mod tests { .get(owned_index) .unwrap() .data() - .get(0) + .first() .unwrap(), (MAX_DEPTH + owned_index) as u8 ); @@ -1451,7 +1451,7 @@ mod tests { .unwrap() .borrow_mut() .data() - .get(0) + .first() .unwrap(); *invoke_context .transaction_context @@ -1471,7 +1471,7 @@ mod tests { .get(not_owned_index) .unwrap() .data() - .get(0) + .first() .unwrap(), data ); diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index 3ff3b925145c86..da68ff6547c0e5 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -540,7 +540,7 @@ impl JsonRpcRequestProcessor { let first_confirmed_block_in_epoch = *self .get_blocks_with_limit(first_slot_in_epoch, 1, config.commitment) .await? - .get(0) + .first() .ok_or(RpcCustomError::BlockNotAvailable { slot: first_slot_in_epoch, })?; diff --git a/rpc/src/rpc_pubsub_service.rs b/rpc/src/rpc_pubsub_service.rs index 7e0521d5f5dcc4..4efc2b0aa12683 100644 --- a/rpc/src/rpc_pubsub_service.rs +++ b/rpc/src/rpc_pubsub_service.rs @@ -193,10 +193,10 @@ pub struct TestBroadcastReceiver { #[cfg(test)] impl TestBroadcastReceiver { pub fn recv(&mut self) -> String { - return match self.recv_timeout(std::time::Duration::from_secs(10)) { + match self.recv_timeout(std::time::Duration::from_secs(10)) { Err(err) => panic!("broadcast receiver error: {}", err), Ok(str) => str, - }; + } } pub fn recv_timeout(&mut self, timeout: std::time::Duration) -> Result { diff --git a/runtime/src/accounts_index.rs b/runtime/src/accounts_index.rs index 5fa1f007843f7e..25fe3e1f3e5b9a 100644 --- a/runtime/src/accounts_index.rs +++ b/runtime/src/accounts_index.rs @@ -333,7 +333,7 @@ impl ReadAccountMapEntry { } pub fn slot_list(&self) -> &SlotList { - &*self.borrow_slot_list_guard() + self.borrow_slot_list_guard() } pub fn ref_count(&self) -> RefCount { diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index 22e11dfdc5b9d5..db749d5a07342b 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2602,7 +2602,7 @@ impl Bank { .filter_map(|id| self.feature_set.activated_slot(id)) .collect::>(); slots.sort_unstable(); - slots.get(0).cloned().unwrap_or_else(|| { + slots.first().cloned().unwrap_or_else(|| { self.feature_set .activated_slot(&feature_set::pico_inflation::id()) .unwrap_or(0) @@ -4699,7 +4699,7 @@ impl Bank { // operations being done and treating them like a signature for (program_id, instruction) in message.program_instructions_iter() { if secp256k1_program::check_id(program_id) || ed25519_program::check_id(program_id) { - if let Some(num_verifies) = instruction.data.get(0) { + if let Some(num_verifies) = instruction.data.first() { num_signatures = num_signatures.saturating_add(u64::from(*num_verifies)); } } diff --git a/runtime/src/hardened_unpack.rs b/runtime/src/hardened_unpack.rs index 887253da46e572..d4ce6916a5c79e 100644 --- a/runtime/src/hardened_unpack.rs +++ b/runtime/src/hardened_unpack.rs @@ -83,7 +83,7 @@ fn check_unpack_result(unpack_result: bool, path: String) -> Result<()> { Ok(()) } -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum UnpackPath<'a> { Valid(&'a Path), Ignore, diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index 30cd82d0cf34d6..2f8a355a4cbc41 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -34,7 +34,7 @@ type SlotDeltaMap = HashMap>; // construct a new one. Usually derived from a status cache's `SlotDeltaMap` pub type SlotDelta = (Slot, bool, Status); -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub struct SignatureConfirmationStatus { pub slot: Slot, pub confirmations: usize, diff --git a/sdk/program/src/message/sanitized.rs b/sdk/program/src/message/sanitized.rs index 4e938eb93f1e61..593a4ac90f08a0 100644 --- a/sdk/program/src/message/sanitized.rs +++ b/sdk/program/src/message/sanitized.rs @@ -257,7 +257,7 @@ impl SanitizedMessage { ) }) .and_then(|ix| { - ix.accounts.get(0).and_then(|idx| { + ix.accounts.first().and_then(|idx| { let idx = *idx as usize; if nonce_must_be_writable && !self.is_writable(idx) { None diff --git a/sdk/program/src/sysvar/mod.rs b/sdk/program/src/sysvar/mod.rs index 881d742b0f6c78..8abfa1aa34dfb4 100644 --- a/sdk/program/src/sysvar/mod.rs +++ b/sdk/program/src/sysvar/mod.rs @@ -137,10 +137,10 @@ macro_rules! impl_sysvar_get { let var_addr = &mut var as *mut _ as *mut u8; #[cfg(target_os = "solana")] - let result = unsafe { crate::syscalls::$syscall_name(var_addr) }; + let result = unsafe { $crate::syscalls::$syscall_name(var_addr) }; #[cfg(not(target_os = "solana"))] - let result = crate::program_stubs::$syscall_name(var_addr); + let result = $crate::program_stubs::$syscall_name(var_addr); match result { $crate::entrypoint::SUCCESS => Ok(var), diff --git a/sdk/src/transaction/mod.rs b/sdk/src/transaction/mod.rs index 79c8e80cd0337d..0041889a5b7277 100644 --- a/sdk/src/transaction/mod.rs +++ b/sdk/src/transaction/mod.rs @@ -1095,7 +1095,7 @@ pub fn uses_durable_nonce(tx: &Transaction) -> Option<&CompiledInstruction> { ) // Nonce account is writable && matches!( - instruction.accounts.get(0), + instruction.accounts.first(), Some(index) if message.is_writable(*index as usize) ) }) @@ -1106,7 +1106,7 @@ pub fn get_nonce_pubkey_from_instruction<'a>( ix: &CompiledInstruction, tx: &'a Transaction, ) -> Option<&'a Pubkey> { - ix.accounts.get(0).and_then(|idx| { + ix.accounts.first().and_then(|idx| { let idx = *idx as usize; tx.message().account_keys.get(idx) }) diff --git a/sdk/src/transaction_context.rs b/sdk/src/transaction_context.rs index 0abfa29529051b..56a5910e4e34fc 100644 --- a/sdk/src/transaction_context.rs +++ b/sdk/src/transaction_context.rs @@ -132,7 +132,7 @@ impl TransactionContext { ) -> Result<&InstructionContext, InstructionError> { let top_level_index = *self .instruction_stack - .get(0) + .first() .ok_or(InstructionError::CallDepth)?; let cpi_index = if level == 0 { 0 diff --git a/validator/src/main.rs b/validator/src/main.rs index e5ae4d62378ee3..f2f1767c0c5ba8 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -259,7 +259,7 @@ fn wait_for_restart_window( leader_schedule.pop_front(); } while upcoming_idle_windows - .get(0) + .first() .map(|(slot, _)| *slot < epoch_info.absolute_slot) .unwrap_or(false) { @@ -276,7 +276,7 @@ fn wait_for_restart_window( if idle_slots >= min_idle_slots { Ok(()) } else { - Err(match upcoming_idle_windows.get(0) { + Err(match upcoming_idle_windows.first() { Some((starting_slot, length_in_slots)) => { format!( "Next idle window in {} slots, for {} slots", diff --git a/zk-token-sdk/src/zk_token_proof_instruction.rs b/zk-token-sdk/src/zk_token_proof_instruction.rs index db0124c2d0dabb..d983454eb1b0d5 100644 --- a/zk-token-sdk/src/zk_token_proof_instruction.rs +++ b/zk-token-sdk/src/zk_token_proof_instruction.rs @@ -73,7 +73,7 @@ impl ProofInstruction { } pub fn decode_type(input: &[u8]) -> Option { - input.get(0).and_then(|x| FromPrimitive::from_u8(*x)) + input.first().and_then(|x| FromPrimitive::from_u8(*x)) } pub fn decode_data(input: &[u8]) -> Option<&T> {