Skip to content

Commit

Permalink
Resolve some new clippy nightly lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Aug 12, 2022
1 parent d6f342f commit ce17f49
Show file tree
Hide file tree
Showing 37 changed files with 58 additions and 74 deletions.
2 changes: 1 addition & 1 deletion account-decoder/src/parse_address_lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn parse_address_lookup_table(
})
}

#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase", tag = "type", content = "info")]
pub enum LookupTableAccountType {
Uninitialized,
Expand Down
10 changes: 3 additions & 7 deletions banks-server/src/banks_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,9 @@ fn verify_transaction(
transaction: &Transaction,
feature_set: &Arc<FeatureSet>,
) -> transaction::Result<()> {
if let Err(err) = transaction.verify() {
Err(err)
} else if let Err(err) = transaction.verify_precompiles(feature_set) {
Err(err)
} else {
Ok(())
}
transaction.verify()?;
transaction.verify_precompiles(feature_set)?;
Ok(())
}

fn simulate_transaction(
Expand Down
2 changes: 1 addition & 1 deletion core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,7 @@ impl BankingStage {
);

retryable_transaction_indexes.extend(execution_results.iter().enumerate().filter_map(
|(index, execution_result)| execution_result.was_executed().then(|| index),
|(index, execution_result)| execution_result.was_executed().then_some(index),
));

return ExecuteAndCommitTransactionsOutput {
Expand Down
2 changes: 1 addition & 1 deletion core/src/sigverify_shreds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn get_slot_leaders(
let leader = leaders.entry(slot).or_insert_with(|| {
let leader = leader_schedule_cache.slot_leader_at(slot, Some(bank))?;
// Discard the shred if the slot leader is the node itself.
(&leader != self_pubkey).then(|| leader)
(&leader != self_pubkey).then_some(leader)
});
if leader.is_none() {
packet.meta.set_discard(true);
Expand Down
2 changes: 1 addition & 1 deletion frozen-abi/src/abi_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ lazy_static! {
impl AbiExample for &Vec<u8> {
fn example() -> Self {
info!("AbiExample for (&Vec<u8>): {}", type_name::<Self>());
&*VEC_U8
&VEC_U8
}
}

Expand Down
2 changes: 1 addition & 1 deletion gossip/src/crds_gossip_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl CrdsGossipPull {
if let Some(ping) = ping {
pings.push((peer.gossip, ping));
}
check.then(|| (weight, peer))
check.then_some((weight, peer))
})
.unzip()
};
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/bigtable_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn upload_confirmed_blocks(
starting_slot, err
)
})?
.map_while(|slot| (slot <= ending_slot).then(|| slot))
.map_while(|slot| (slot <= ending_slot).then_some(slot))
.collect();

if blockstore_slots.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3145,7 +3145,7 @@ impl Blockstore {
}
.expect("fetch from DuplicateSlots column family failed")?;
let new_shred = Shred::new_from_serialized_shred(payload).unwrap();
(existing_shred != *new_shred.payload()).then(|| existing_shred)
(existing_shred != *new_shred.payload()).then_some(existing_shred)
}

pub fn has_duplicate_shreds_in_slot(&self, slot: Slot) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/blockstore_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod serde_compat {
D: Deserializer<'de>,
{
let val = u64::deserialize(deserializer)?;
Ok((val != u64::MAX).then(|| val))
Ok((val != u64::MAX).then_some(val))
}
}

Expand Down
2 changes: 1 addition & 1 deletion ledger/src/shred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ pub mod layout {
merkle::ShredData::get_signed_message_range(proof_size)?
}
};
(shred.len() <= range.end).then(|| range)
(shred.len() <= range.end).then_some(range)
}

pub(crate) fn get_reference_tick(shred: &[u8]) -> Result<u8, Error> {
Expand Down
2 changes: 1 addition & 1 deletion ledger/src/shred/shred_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub(super) fn erasure_shard_index<T: ShredCodeTrait>(shred: &T) -> Option<usize>
let position = usize::from(coding_header.position);
let fec_set_size = num_data_shreds.checked_add(num_coding_shreds)?;
let index = position.checked_add(num_data_shreds)?;
(index < fec_set_size).then(|| index)
(index < fec_set_size).then_some(index)
}

pub(super) fn sanitize<T: ShredCodeTrait>(shred: &T) -> Result<(), Error> {
Expand Down
2 changes: 1 addition & 1 deletion local-cluster/src/local_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl LocalCluster {
})
.collect();
for (stake, validator_config, (key, _)) in izip!(
(&config.node_stakes[1..]).iter(),
config.node_stakes[1..].iter(),
config.validator_configs[1..].iter(),
validator_keys[1..].iter(),
) {
Expand Down
7 changes: 1 addition & 6 deletions perf/src/sigverify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,7 @@ mod tests {
pub fn memfind<A: Eq>(a: &[A], b: &[A]) -> Option<usize> {
assert!(a.len() >= b.len());
let end = a.len() - b.len() + 1;
for i in 0..end {
if a[i..i + b.len()] == b[..] {
return Some(i);
}
}
None
(0..end).find(|&i| a[i..i + b.len()] == b[..])
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion poh/src/poh_recorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ impl PohRecorder {
start: Arc::new(Instant::now()),
min_tick_height: bank.tick_height(),
max_tick_height: bank.max_tick_height(),
transaction_index: track_transaction_indexes.then(|| 0),
transaction_index: track_transaction_indexes.then_some(0),
};
trace!("new working bank");
assert_eq!(working_bank.bank.ticks_per_slot(), self.ticks_per_slot());
Expand Down
6 changes: 2 additions & 4 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn new_response<T>(bank: &Bank, value: T) -> RpcResponse<T> {
/// Wrapper for rpc return types of methods that provide responses both with and without context.
/// Main purpose of this is to fix methods that lack context information in their return type,
/// without breaking backwards compatibility.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OptionalContext<T> {
Context(RpcResponse<T>),
Expand Down Expand Up @@ -3646,9 +3646,7 @@ pub mod rpc_full {
}

if !skip_preflight {
if let Err(e) = verify_transaction(&transaction, &preflight_bank.feature_set) {
return Err(e);
}
verify_transaction(&transaction, &preflight_bank.feature_set)?;

match meta.health.check() {
RpcHealthStatus::Ok => (),
Expand Down
5 changes: 1 addition & 4 deletions rpc/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,10 +1001,7 @@ impl RpcSubscriptions {
let mut slots_to_notify: Vec<_> =
(*w_last_unnotified_slot..slot).collect();
let ancestors = bank.proper_ancestors_set();
slots_to_notify = slots_to_notify
.into_iter()
.filter(|slot| ancestors.contains(slot))
.collect();
slots_to_notify.retain(|slot| ancestors.contains(slot));
slots_to_notify.push(slot);
for s in slots_to_notify {
// To avoid skipping a slot that fails this condition,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/account_rent_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub(crate) fn check_rent_state(
.get_account_at_index(index)
.expect(expect_msg)
.borrow(),
include_account_index_in_err.then(|| index),
include_account_index_in_err.then_some(index),
prevent_crediting_accounts_that_end_rent_paying,
)?;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl Accounts {
payer_account,
feature_set
.is_active(&feature_set::include_account_index_in_rent_error::ID)
.then(|| payer_index),
.then_some(payer_index),
feature_set
.is_active(&feature_set::prevent_crediting_accounts_that_end_rent_paying::id()),
)
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2174,7 +2174,7 @@ impl AccountsDb {
// figure out how many ancient accounts have been reclaimed
let old_reclaims = reclaims
.iter()
.filter_map(|(slot, _)| (slot < &one_epoch_old).then(|| 1))
.filter_map(|(slot, _)| (slot < &one_epoch_old).then_some(1))
.sum();
ancient_account_cleans.fetch_add(old_reclaims, Ordering::Relaxed);
reclaims
Expand Down Expand Up @@ -2392,7 +2392,7 @@ impl AccountsDb {
.iter()
.filter_map(|entry| {
let slot = *entry.key();
(slot <= max_slot).then(|| slot)
(slot <= max_slot).then_some(slot)
})
.collect()
}
Expand Down Expand Up @@ -3671,7 +3671,7 @@ impl AccountsDb {
) -> Option<SnapshotStorage> {
self.get_storages_for_slot(slot).and_then(|all_storages| {
self.should_move_to_ancient_append_vec(&all_storages, current_ancient, slot)
.then(|| all_storages)
.then_some(all_storages)
})
}

Expand Down Expand Up @@ -5307,7 +5307,7 @@ impl AccountsDb {
// with the same slot.
let is_being_flushed = !currently_contended_slots.insert(*remove_slot);
// If the cache is currently flushing this slot, add it to the list
is_being_flushed.then(|| remove_slot)
is_being_flushed.then_some(remove_slot)
})
.cloned()
.collect();
Expand Down
12 changes: 6 additions & 6 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2260,7 +2260,7 @@ impl Bank {
hash: *self.hash.read().unwrap(),
parent_hash: self.parent_hash,
parent_slot: self.parent_slot,
hard_forks: &*self.hard_forks,
hard_forks: &self.hard_forks,
transaction_count: self.transaction_count.load(Relaxed),
tick_height: self.tick_height.load(Relaxed),
signature_count: self.signature_count.load(Relaxed),
Expand Down Expand Up @@ -3268,7 +3268,7 @@ impl Bank {
let vote_state = account.vote_state();
let vote_state = vote_state.as_ref().ok()?;
let slot_delta = self.slot().checked_sub(vote_state.last_timestamp.slot)?;
(slot_delta <= slots_per_epoch).then(|| {
(slot_delta <= slots_per_epoch).then_some({
(
*pubkey,
(
Expand Down Expand Up @@ -3942,10 +3942,10 @@ impl Bank {
}

/// Prepare a transaction batch without locking accounts for transaction simulation.
pub(crate) fn prepare_simulation_batch<'a>(
&'a self,
pub(crate) fn prepare_simulation_batch(
&self,
transaction: SanitizedTransaction,
) -> TransactionBatch<'a, '_> {
) -> TransactionBatch<'_, '_> {
let tx_account_lock_limit = self.get_transaction_account_lock_limit();
let lock_result = transaction
.get_account_locks(tx_account_lock_limit)
Expand Down Expand Up @@ -4346,7 +4346,7 @@ impl Bank {
self.feature_set.clone(),
compute_budget,
timings,
&*self.sysvar_cache.read().unwrap(),
&self.sysvar_cache.read().unwrap(),
blockhash,
lamports_per_signature,
prev_accounts_data_len,
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/expected_rent_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ pub mod tests {
);
assert_eq!(
result,
(!leave_alone).then(|| ExpectedRentCollection {
(!leave_alone).then_some(ExpectedRentCollection {
partition_from_pubkey,
epoch_of_max_storage_slot: rent_collector.epoch,
partition_index_from_max_slot: partition_index_max_inclusive,
Expand Down Expand Up @@ -712,7 +712,7 @@ pub mod tests {
);
assert_eq!(
result,
(!greater).then(|| ExpectedRentCollection {
(!greater).then_some(ExpectedRentCollection {
partition_from_pubkey,
epoch_of_max_storage_slot: rent_collector.epoch,
partition_index_from_max_slot: partition_index_max_inclusive,
Expand Down Expand Up @@ -909,7 +909,7 @@ pub mod tests {
);
assert_eq!(
result,
(account_rent_epoch != 0).then(|| ExpectedRentCollection {
(account_rent_epoch != 0).then_some(ExpectedRentCollection {
partition_from_pubkey,
epoch_of_max_storage_slot: rent_collector.epoch + 1,
partition_index_from_max_slot: partition_index_max_inclusive,
Expand Down Expand Up @@ -1084,7 +1084,7 @@ pub mod tests {
};
assert_eq!(
result,
some_expected.then(|| ExpectedRentCollection {
some_expected.then_some(ExpectedRentCollection {
partition_from_pubkey,
epoch_of_max_storage_slot: rent_collector.epoch,
partition_index_from_max_slot,
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 @@ -384,7 +384,7 @@ where
.map(|path_buf| path_buf.as_path())
{
Some(path) => {
accounts_path_processor(*file, path);
accounts_path_processor(file, path);
UnpackPath::Valid(path)
}
None => UnpackPath::Invalid,
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/in_mem_accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ impl<'a> FlushGuard<'a> {
#[must_use = "if unused, the `flushing` flag will immediately clear"]
fn lock(flushing: &'a AtomicBool) -> Option<Self> {
let already_flushing = flushing.swap(true, Ordering::AcqRel);
(!already_flushing).then(|| Self { flushing })
(!already_flushing).then_some(Self { flushing })
}
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/serde_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub(crate) enum SerdeStyle {

const MAX_STREAM_SIZE: u64 = 32 * 1024 * 1024 * 1024;

#[derive(Clone, Debug, Default, Deserialize, Serialize, AbiExample, PartialEq)]
#[derive(Clone, Debug, Default, Deserialize, Serialize, AbiExample, PartialEq, Eq)]
pub struct AccountsDbFields<T>(
HashMap<Slot, Vec<T>>,
StoredMetaWriteVersion,
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<T> SnapshotAccountsDbFields<T> {
// There must not be any overlap in the slots of storages between the full snapshot and the incremental snapshot
incremental_snapshot_storages
.iter()
.all(|storage_entry| !full_snapshot_storages.contains_key(storage_entry.0)).then(|| ()).ok_or_else(|| {
.all(|storage_entry| !full_snapshot_storages.contains_key(storage_entry.0)).then_some(()).ok_or_else(|| {
io::Error::new(io::ErrorKind::InvalidData, "Snapshots are incompatible: There are storages for the same slot in both the full snapshot and the incremental snapshot!")
})?;

Expand Down
4 changes: 2 additions & 2 deletions runtime/src/serde_snapshot/newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'a> TypeContext<'a> for Context {
(
SerializableVersionedBank::from(fields),
SerializableAccountsDb::<'a, Self> {
accounts_db: &*serializable_bank.bank.rc.accounts.accounts_db,
accounts_db: &serializable_bank.bank.rc.accounts.accounts_db,
slot: serializable_bank.bank.rc.slot,
account_storage_entries: serializable_bank.snapshot_storages,
phantom: std::marker::PhantomData::default(),
Expand All @@ -226,7 +226,7 @@ impl<'a> TypeContext<'a> for Context {
(
SerializableVersionedBank::from(fields),
SerializableAccountsDb::<'a, Self> {
accounts_db: &*serializable_bank.bank.rc.accounts.accounts_db,
accounts_db: &serializable_bank.bank.rc.accounts.accounts_db,
slot: serializable_bank.bank.rc.slot,
account_storage_entries: serializable_bank.snapshot_storages,
phantom: std::marker::PhantomData::default(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/serde_snapshot/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn test_accounts_serialize_style(serde_style: SerdeStyle) {
accountsdb_to_stream(
serde_style,
&mut writer,
&*accounts.accounts_db,
&accounts.accounts_db,
0,
&accounts.accounts_db.get_snapshot_storages(0, None, None).0,
)
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/snapshot_minimizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ mod tests {
.accounts
.iter()
.filter_map(|(pubkey, account)| {
stake::program::check_id(account.owner()).then(|| *pubkey)
stake::program::check_id(account.owner()).then_some(*pubkey)
})
.collect();
expected_stake_accounts.push(bootstrap_validator_pubkey);
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/snapshot_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ fn check_are_snapshots_compatible(
let incremental_snapshot_archive_info = incremental_snapshot_archive_info.unwrap();

(full_snapshot_archive_info.slot() == incremental_snapshot_archive_info.base_slot())
.then(|| ())
.then_some(())
.ok_or_else(|| {
SnapshotError::MismatchedBaseSlot(
full_snapshot_archive_info.slot(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/storable_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub mod tests {
slot,
&vec![(&pk, &account, slot), (&pk, &account, slot)][..],
);
assert!(!(&test3).contains_multiple_slots());
assert!(!test3.contains_multiple_slots());
let test3 = (
slot,
&vec![(&pk, &account, slot), (&pk, &account, slot + 1)][..],
Expand Down
Loading

0 comments on commit ce17f49

Please sign in to comment.