Skip to content

Commit

Permalink
clippy: add cloned_instead_of_copied clippy lint (paradigmxyz#10530)
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Seitz <[email protected]>
Co-authored-by: Oliver <[email protected]>
  • Loading branch information
3 people authored Aug 26, 2024
1 parent 042faac commit 29058ad
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ unused_rounding = "warn"
use_self = "warn"
useless_let_if_seq = "warn"
zero_sized_map_values = "warn"
cloned_instead_of_copied = "warn"
option_as_ref_cloned = "warn"

# These are nursery lints which have findings. Allow them for now. Some are not
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/block_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl BlockIndices {

/// Get the [`SidechainId`] for the given block hash if it exists.
pub(crate) fn get_side_chain_id(&self, block: &BlockHash) -> Option<SidechainId> {
self.blocks_to_chain.get(block).cloned()
self.blocks_to_chain.get(block).copied()
}

/// Update all block hashes. iterate over present and new list of canonical hashes and compare
Expand Down
6 changes: 3 additions & 3 deletions crates/blockchain-tree/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ impl<'a> ExecutionDataProvider for BundleStateDataRef<'a> {
}

fn block_hash(&self, block_number: BlockNumber) -> Option<BlockHash> {
let block_hash = self.sidechain_block_hashes.get(&block_number).cloned();
let block_hash = self.sidechain_block_hashes.get(&block_number).copied();
if block_hash.is_some() {
return block_hash
}

self.canonical_block_hashes.get(&block_number).cloned()
self.canonical_block_hashes.get(&block_number).copied()
}
}

Expand Down Expand Up @@ -57,7 +57,7 @@ impl ExecutionDataProvider for ExecutionData {
}

fn block_hash(&self, block_number: BlockNumber) -> Option<BlockHash> {
self.parent_block_hashes.get(&block_number).cloned()
self.parent_block_hashes.get(&block_number).copied()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/canonical_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl CanonicalChain {
/// Returns the block hash of the (non-finalized) canonical block with the given number.
#[inline]
pub(crate) fn canonical_hash(&self, number: &BlockNumber) -> Option<BlockHash> {
self.chain.get(number).cloned()
self.chain.get(number).copied()
}

/// Returns the block number of the (non-finalized) canonical block with the given hash.
Expand Down
2 changes: 1 addition & 1 deletion crates/chain-state/src/in_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl InMemoryState {

/// Returns the hash for a specific block number
pub(crate) fn hash_by_number(&self, number: u64) -> Option<B256> {
self.numbers.read().get(&number).cloned()
self.numbers.read().get(&number).copied()
}

/// Returns the current chain head state.
Expand Down
4 changes: 2 additions & 2 deletions crates/revm/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl AccountReader for StateProviderTest {

impl BlockHashReader for StateProviderTest {
fn block_hash(&self, number: u64) -> ProviderResult<Option<B256>> {
Ok(self.block_hash.get(&number).cloned())
Ok(self.block_hash.get(&number).copied())
}

fn canonical_hashes_range(
Expand Down Expand Up @@ -134,7 +134,7 @@ impl StateProvider for StateProviderTest {
account: Address,
storage_key: StorageKey,
) -> ProviderResult<Option<reth_primitives::StorageValue>> {
Ok(self.accounts.get(&account).and_then(|(storage, _)| storage.get(&storage_key).cloned()))
Ok(self.accounts.get(&account).and_then(|(storage, _)| storage.get(&storage_key).copied()))
}

fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-engine-api/src/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct EngineCapabilities {
impl EngineCapabilities {
/// Returns the list of all supported Engine capabilities for Prague spec.
fn prague() -> Self {
Self { inner: CAPABILITIES.iter().cloned().map(str::to_owned).collect() }
Self { inner: CAPABILITIES.iter().copied().map(str::to_owned).collect() }
}

/// Returns the list of all supported Engine capabilities.
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-eth-api/src/helpers/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub trait EthFees: LoadFee {
// Calculate the index in the precomputed rewards array
let index = (clamped_percentile / (1.0 / resolution as f64)).round() as usize;
// Fetch the reward from the FeeHistoryEntry
entry.rewards.get(index).cloned().unwrap_or_default()
entry.rewards.get(index).copied().unwrap_or_default()
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/otterscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ where

// A contract maybe created and then destroyed in multiple transactions, here we
// return the first found transaction, this behavior is consistent with etherscan's
let found = traces.and_then(|traces| traces.first().cloned());
let found = traces.and_then(|traces| traces.first().copied());
Ok(found)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/storage/provider/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ impl StateProvider for MockEthProvider {
storage_key: StorageKey,
) -> ProviderResult<Option<StorageValue>> {
let lock = self.accounts.lock();
Ok(lock.get(&account).and_then(|account| account.storage.get(&storage_key)).cloned())
Ok(lock.get(&account).and_then(|account| account.storage.get(&storage_key)).copied())
}

fn bytecode_by_hash(&self, code_hash: B256) -> ProviderResult<Option<Bytecode>> {
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/parked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl<T: ParkedOrd> ParkedPool<T> {
pub(crate) fn get_senders_by_submission_id(
&self,
) -> impl Iterator<Item = SubmissionSenderId> + '_ {
self.last_sender_submission.iter().cloned()
self.last_sender_submission.iter().copied()
}

/// Truncates the pool by removing transactions, until the given [`SubPoolLimit`] has been met.
Expand Down
4 changes: 2 additions & 2 deletions crates/trie/parallel/benches/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ fn generate_test_data(size: usize) -> (HashedPostState, HashedPostState) {
.unwrap()
.current();

let keys = db_state.keys().cloned().collect::<Vec<_>>();
let keys = db_state.keys().copied().collect::<Vec<_>>();
let keys_to_update = subsequence(keys, size / 2).new_tree(&mut runner).unwrap().current();

let updated_storages = keys_to_update
.into_iter()
.map(|address| {
let (_, storage) = db_state.get(&address).unwrap();
let slots = storage.keys().cloned().collect::<Vec<_>>();
let slots = storage.keys().copied().collect::<Vec<_>>();
let slots_to_update =
subsequence(slots, storage_size / 2).new_tree(&mut runner).unwrap().current();
(
Expand Down
2 changes: 1 addition & 1 deletion testing/testing-utils/src/generators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub fn random_account_change<R: Rng>(
n_storage_changes: Range<u64>,
key_range: Range<u64>,
) -> (Address, Address, U256, Vec<StorageEntry>) {
let mut addresses = valid_addresses.choose_multiple(rng, 2).cloned();
let mut addresses = valid_addresses.choose_multiple(rng, 2).copied();

let addr_from = addresses.next().unwrap_or_else(Address::random);
let addr_to = addresses.next().unwrap_or_else(Address::random);
Expand Down

0 comments on commit 29058ad

Please sign in to comment.