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

Remove some new nightly clippy lints #26115

Merged
merged 1 commit into from
Jun 22, 2022
Merged
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
2 changes: 1 addition & 1 deletion account-decoder/src/parse_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl From<StakeConfig> for UiStakeConfig {
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UiConfig<T> {
pub keys: Vec<UiConfigKey>,
Expand Down
4 changes: 3 additions & 1 deletion ci/test-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion cli/src/cluster_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion client/src/rpc_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ pub struct RpcSignaturesForAddressConfig {
pub min_context_slot: Option<Slot>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RpcEncodingConfigWrapper<T> {
Deprecated(Option<UiTransactionEncoding>),
Expand Down
4 changes: 2 additions & 2 deletions client/src/rpc_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ impl RpcResponseContext {
}
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Response<T> {
pub context: RpcResponseContext,
pub value: T,
}

#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RpcBlockCommitment<T> {
pub commitment: Option<T>,
Expand Down
4 changes: 2 additions & 2 deletions core/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ impl Tower {

pub fn last_voted_slot_in_bank(bank: &Bank, vote_account_pubkey: &Pubkey) -> Option<Slot> {
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<Slot> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

Expand Down
6 changes: 3 additions & 3 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3532,7 +3532,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::<cf::SlotMeta>(*slot, meta)?;
}
Ok(())
Expand Down Expand Up @@ -3621,8 +3621,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
Expand Down
1 change: 1 addition & 0 deletions ledger/src/shred/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion perf/benches/shrink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn test_packet_with_size(size: usize, rng: &mut ThreadRng) -> Vec<u8> {
fn do_bench_shrink_packets(bencher: &mut Bencher, mut batches: Vec<PacketBatch>) {
// 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()))
Expand Down
6 changes: 3 additions & 3 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ mod tests {
.get(owned_index)
.unwrap()
.data()
.get(0)
.first()
.unwrap(),
(MAX_DEPTH + owned_index) as u8
);
Expand All @@ -1451,7 +1451,7 @@ mod tests {
.unwrap()
.borrow_mut()
.data()
.get(0)
.first()
.unwrap();
*invoke_context
.transaction_context
Expand All @@ -1471,7 +1471,7 @@ mod tests {
.get(not_owned_index)
.unwrap()
.data()
.get(0)
.first()
.unwrap(),
data
);
Expand Down
2 changes: 1 addition & 1 deletion rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})?;
Expand Down
4 changes: 2 additions & 2 deletions rpc/src/rpc_pubsub_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> {
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl<T: IndexValue> ReadAccountMapEntry<T> {
}

pub fn slot_list(&self) -> &SlotList<T> {
&*self.borrow_slot_list_guard()
self.borrow_slot_list_guard()
}

pub fn ref_count(&self) -> RefCount {
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2599,7 +2599,7 @@ impl Bank {
.filter_map(|id| self.feature_set.activated_slot(id))
.collect::<Vec<_>>();
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)
Expand Down Expand Up @@ -4715,7 +4715,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));
}
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/hardened_unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion sdk/program/src/message/sanitized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdk/program/src/sysvar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
})
Expand All @@ -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)
})
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion zk-token-sdk/src/zk_token_proof_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl ProofInstruction {
}

pub fn decode_type(input: &[u8]) -> Option<Self> {
input.get(0).and_then(|x| FromPrimitive::from_u8(*x))
input.first().and_then(|x| FromPrimitive::from_u8(*x))
}

pub fn decode_data<T: Pod>(input: &[u8]) -> Option<&T> {
Expand Down