clippy: add cloned_instead_of_copied clippy lint (#10530)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: Oliver <onbjerg@users.noreply.github.com>
This commit is contained in:
Thomas Coratger
2024-08-26 02:04:19 -07:00
committed by GitHub
parent 042faacb15
commit 29058ad7ee
13 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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()
}
}
@ -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()
}
}

View File

@ -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.

View File

@ -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.

View File

@ -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(
@ -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>> {

View File

@ -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.

View File

@ -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()
}
}

View File

@ -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)
}
}

View File

@ -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>> {

View File

@ -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.

View File

@ -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();
(

View File

@ -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);