From 738dc8460e9b882332f0cb711efdab585ac72f46 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bastian=20K=C3=B6cher?= <git@kchr.de>
Date: Tue, 18 Oct 2022 12:07:02 +0200
Subject: [PATCH] Prepare for latest clippy (nightly 09-10-2022) (#12466)

---
 substrate/client/api/src/in_mem.rs                 |  2 +-
 substrate/client/consensus/slots/src/lib.rs        |  2 +-
 substrate/client/db/src/bench.rs                   |  2 +-
 substrate/client/db/src/lib.rs                     |  2 +-
 substrate/client/network/sync/src/lib.rs           |  3 +--
 substrate/client/state-db/src/pruning.rs           |  2 +-
 .../client/transaction-pool/src/graph/pool.rs      |  6 +++---
 substrate/frame/transaction-payment/src/lib.rs     |  8 ++++----
 substrate/primitives/runtime/src/generic/era.rs    |  4 ++--
 .../runtime/src/offchain/storage_lock.rs           | 14 ++++++--------
 .../state-machine/src/in_memory_backend.rs         |  4 ++--
 .../state-machine/src/overlayed_changes/mod.rs     |  2 +-
 substrate/primitives/trie/src/recorder.rs          |  2 +-
 substrate/test-utils/runtime/client/src/lib.rs     |  2 +-
 .../frame/benchmarking-cli/src/pallet/command.rs   |  5 ++---
 15 files changed, 28 insertions(+), 32 deletions(-)

diff --git a/substrate/client/api/src/in_mem.rs b/substrate/client/api/src/in_mem.rs
index 9cea1883bdc..99efdd3bf1d 100644
--- a/substrate/client/api/src/in_mem.rs
+++ b/substrate/client/api/src/in_mem.rs
@@ -516,7 +516,7 @@ where
 	) -> sp_blockchain::Result<Block::Hash> {
 		check_genesis_storage(&storage)?;
 
-		let child_delta = storage.children_default.iter().map(|(_storage_key, child_content)| {
+		let child_delta = storage.children_default.values().map(|child_content| {
 			(
 				&child_content.child_info,
 				child_content.data.iter().map(|(k, v)| (k.as_ref(), Some(v.as_ref()))),
diff --git a/substrate/client/consensus/slots/src/lib.rs b/substrate/client/consensus/slots/src/lib.rs
index 6225bbbda17..90bfef6c160 100644
--- a/substrate/client/consensus/slots/src/lib.rs
+++ b/substrate/client/consensus/slots/src/lib.rs
@@ -1118,7 +1118,7 @@ mod test {
 
 		// But lets assert all distances, which we expect to grow linearly until `max_interval + 1`
 		let expected_intervals: Vec<_> =
-			(0..497).map(|i| (i / 2).max(1).min(expected_distance)).collect();
+			(0..497).map(|i| (i / 2).clamp(1, expected_distance)).collect();
 
 		assert_eq!(intervals, expected_intervals);
 	}
diff --git a/substrate/client/db/src/bench.rs b/substrate/client/db/src/bench.rs
index b1f4e3b6c0a..13d91fff0b5 100644
--- a/substrate/client/db/src/bench.rs
+++ b/substrate/client/db/src/bench.rs
@@ -116,7 +116,7 @@ impl<B: BlockT> BenchmarkingState<B> {
 		state.add_whitelist_to_tracker();
 
 		state.reopen()?;
-		let child_delta = genesis.children_default.iter().map(|(_storage_key, child_content)| {
+		let child_delta = genesis.children_default.values().map(|child_content| {
 			(
 				&child_content.child_info,
 				child_content.data.iter().map(|(k, v)| (k.as_ref(), Some(v.as_ref()))),
diff --git a/substrate/client/db/src/lib.rs b/substrate/client/db/src/lib.rs
index ae777ad154f..1a80c16c4e5 100644
--- a/substrate/client/db/src/lib.rs
+++ b/substrate/client/db/src/lib.rs
@@ -798,7 +798,7 @@ impl<Block: BlockT> BlockImportOperation<Block> {
 			return Err(sp_blockchain::Error::InvalidState)
 		}
 
-		let child_delta = storage.children_default.iter().map(|(_storage_key, child_content)| {
+		let child_delta = storage.children_default.values().map(|child_content| {
 			(
 				&child_content.child_info,
 				child_content.data.iter().map(|(k, v)| (&k[..], Some(&v[..]))),
diff --git a/substrate/client/network/sync/src/lib.rs b/substrate/client/network/sync/src/lib.rs
index 64d9d4d668e..e9c2b24b2ba 100644
--- a/substrate/client/network/sync/src/lib.rs
+++ b/substrate/client/network/sync/src/lib.rs
@@ -1444,8 +1444,7 @@ where
 		if let SyncMode::LightState { skip_proofs, .. } = &self.mode {
 			if self.state_sync.is_none() && !self.peers.is_empty() && self.queue_blocks.is_empty() {
 				// Finalized a recent block.
-				let mut heads: Vec<_> =
-					self.peers.iter().map(|(_, peer)| peer.best_number).collect();
+				let mut heads: Vec<_> = self.peers.values().map(|peer| peer.best_number).collect();
 				heads.sort();
 				let median = heads[heads.len() / 2];
 				if number + STATE_SYNC_FINALITY_THRESHOLD.saturated_into() >= median {
diff --git a/substrate/client/state-db/src/pruning.rs b/substrate/client/state-db/src/pruning.rs
index 2c231109104..50a46def595 100644
--- a/substrate/client/state-db/src/pruning.rs
+++ b/substrate/client/state-db/src/pruning.rs
@@ -117,7 +117,7 @@ impl<BlockHash: Hash, Key: Hash, D: MetaDb> DeathRowQueue<BlockHash, Key, D> {
 		window_size: u32,
 	) -> Result<DeathRowQueue<BlockHash, Key, D>, Error<D::Error>> {
 		// limit the cache capacity from 1 to `DEFAULT_MAX_BLOCK_CONSTRAINT`
-		let cache_capacity = window_size.max(1).min(DEFAULT_MAX_BLOCK_CONSTRAINT) as usize;
+		let cache_capacity = window_size.clamp(1, DEFAULT_MAX_BLOCK_CONSTRAINT) as usize;
 		let mut cache = VecDeque::with_capacity(cache_capacity);
 		trace!(target: "state-db", "Reading pruning journal for the database-backed queue. Pending #{}", base);
 		// Load block from db
diff --git a/substrate/client/transaction-pool/src/graph/pool.rs b/substrate/client/transaction-pool/src/graph/pool.rs
index 9afceffe8dd..d311e0d0c8f 100644
--- a/substrate/client/transaction-pool/src/graph/pool.rs
+++ b/substrate/client/transaction-pool/src/graph/pool.rs
@@ -168,7 +168,7 @@ impl<B: ChainApi> Pool<B> {
 	) -> Result<Vec<Result<ExtrinsicHash<B>, B::Error>>, B::Error> {
 		let xts = xts.into_iter().map(|xt| (source, xt));
 		let validated_transactions = self.verify(at, xts, CheckBannedBeforeVerify::Yes).await?;
-		Ok(self.validated_pool.submit(validated_transactions.into_iter().map(|(_, tx)| tx)))
+		Ok(self.validated_pool.submit(validated_transactions.into_values()))
 	}
 
 	/// Resubmit the given extrinsics to the pool.
@@ -182,7 +182,7 @@ impl<B: ChainApi> Pool<B> {
 	) -> Result<Vec<Result<ExtrinsicHash<B>, B::Error>>, B::Error> {
 		let xts = xts.into_iter().map(|xt| (source, xt));
 		let validated_transactions = self.verify(at, xts, CheckBannedBeforeVerify::No).await?;
-		Ok(self.validated_pool.submit(validated_transactions.into_iter().map(|(_, tx)| tx)))
+		Ok(self.validated_pool.submit(validated_transactions.into_values()))
 	}
 
 	/// Imports one unverified extrinsic to the pool
@@ -349,7 +349,7 @@ impl<B: ChainApi> Pool<B> {
 			at,
 			known_imported_hashes,
 			pruned_hashes,
-			reverified_transactions.into_iter().map(|(_, xt)| xt).collect(),
+			reverified_transactions.into_values().collect(),
 		)
 	}
 
diff --git a/substrate/frame/transaction-payment/src/lib.rs b/substrate/frame/transaction-payment/src/lib.rs
index ce85bf93a90..5027db41ec0 100644
--- a/substrate/frame/transaction-payment/src/lib.rs
+++ b/substrate/frame/transaction-payment/src/lib.rs
@@ -228,11 +228,11 @@ where
 
 		if positive {
 			let excess = first_term.saturating_add(second_term).saturating_mul(previous);
-			previous.saturating_add(excess).max(min_multiplier).min(max_multiplier)
+			previous.saturating_add(excess).clamp(min_multiplier, max_multiplier)
 		} else {
 			// Defensive-only: first_term > second_term. Safe subtraction.
 			let negative = first_term.saturating_sub(second_term).saturating_mul(previous);
-			previous.saturating_sub(negative).max(min_multiplier).min(max_multiplier)
+			previous.saturating_sub(negative).clamp(min_multiplier, max_multiplier)
 		}
 	}
 }
@@ -713,8 +713,8 @@ where
 		let max_block_weight = max_block_weight.ref_time();
 		let info_weight = info.weight.ref_time();
 
-		let bounded_weight = info_weight.max(1).min(max_block_weight);
-		let bounded_length = (len as u64).max(1).min(max_block_length);
+		let bounded_weight = info_weight.clamp(1, max_block_weight);
+		let bounded_length = (len as u64).clamp(1, max_block_length);
 
 		let max_tx_per_block_weight = max_block_weight / bounded_weight;
 		let max_tx_per_block_length = max_block_length / bounded_length;
diff --git a/substrate/primitives/runtime/src/generic/era.rs b/substrate/primitives/runtime/src/generic/era.rs
index 2ca50b12b2e..b26545fb840 100644
--- a/substrate/primitives/runtime/src/generic/era.rs
+++ b/substrate/primitives/runtime/src/generic/era.rs
@@ -63,7 +63,7 @@ impl Era {
 	/// does not exceed `BlockHashCount` parameter passed to `system` module, since that
 	/// prunes old blocks and renders transactions immediately invalid.
 	pub fn mortal(period: u64, current: u64) -> Self {
-		let period = period.checked_next_power_of_two().unwrap_or(1 << 16).max(4).min(1 << 16);
+		let period = period.checked_next_power_of_two().unwrap_or(1 << 16).clamp(4, 1 << 16);
 		let phase = current % period;
 		let quantize_factor = (period >> 12).max(1);
 		let quantized_phase = phase / quantize_factor * quantize_factor;
@@ -105,7 +105,7 @@ impl Encode for Era {
 			Self::Immortal => output.push_byte(0),
 			Self::Mortal(period, phase) => {
 				let quantize_factor = (*period as u64 >> 12).max(1);
-				let encoded = (period.trailing_zeros() - 1).max(1).min(15) as u16 |
+				let encoded = (period.trailing_zeros() - 1).clamp(1, 15) as u16 |
 					((phase / quantize_factor) << 4) as u16;
 				encoded.encode_to(output);
 			},
diff --git a/substrate/primitives/runtime/src/offchain/storage_lock.rs b/substrate/primitives/runtime/src/offchain/storage_lock.rs
index 4ea90307452..47325743bd2 100644
--- a/substrate/primitives/runtime/src/offchain/storage_lock.rs
+++ b/substrate/primitives/runtime/src/offchain/storage_lock.rs
@@ -77,8 +77,8 @@ const STORAGE_LOCK_DEFAULT_EXPIRY_DURATION: Duration = Duration::from_millis(20_
 const STORAGE_LOCK_DEFAULT_EXPIRY_BLOCKS: u32 = 4;
 
 /// Time between checks if the lock is still being held in milliseconds.
-const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN: Duration = Duration::from_millis(100);
-const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX: Duration = Duration::from_millis(10);
+const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN: Duration = Duration::from_millis(10);
+const STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX: Duration = Duration::from_millis(100);
 
 /// Lockable item for use with a persisted storage lock.
 ///
@@ -137,10 +137,9 @@ impl Lockable for Time {
 		let remainder: Duration = now.diff(deadline);
 		// do not snooze the full duration, but instead snooze max 100ms
 		// it might get unlocked in another thread
-		use core::cmp::{max, min};
-		let snooze = max(
-			min(remainder, STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX),
+		let snooze = remainder.clamp(
 			STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN,
+			STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX,
 		);
 		sp_io::offchain::sleep_until(now.add(snooze));
 	}
@@ -239,10 +238,9 @@ impl<B: BlockNumberProvider> Lockable for BlockAndTime<B> {
 	fn snooze(deadline: &Self::Deadline) {
 		let now = offchain::timestamp();
 		let remainder: Duration = now.diff(&(deadline.timestamp));
-		use core::cmp::{max, min};
-		let snooze = max(
-			min(remainder, STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX),
+		let snooze = remainder.clamp(
 			STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MIN,
+			STORAGE_LOCK_PER_CHECK_ITERATION_SNOOZE_MAX,
 		);
 		sp_io::offchain::sleep_until(now.add(snooze));
 	}
diff --git a/substrate/primitives/state-machine/src/in_memory_backend.rs b/substrate/primitives/state-machine/src/in_memory_backend.rs
index e205e83e855..06714fb4140 100644
--- a/substrate/primitives/state-machine/src/in_memory_backend.rs
+++ b/substrate/primitives/state-machine/src/in_memory_backend.rs
@@ -157,8 +157,8 @@ where
 	fn from((inners, state_version): (Storage, StateVersion)) -> Self {
 		let mut inner: HashMap<Option<ChildInfo>, BTreeMap<StorageKey, StorageValue>> = inners
 			.children_default
-			.into_iter()
-			.map(|(_k, c)| (Some(c.child_info), c.data))
+			.into_values()
+			.map(|c| (Some(c.child_info), c.data))
 			.collect();
 		inner.insert(None, inners.top);
 		(inner, state_version).into()
diff --git a/substrate/primitives/state-machine/src/overlayed_changes/mod.rs b/substrate/primitives/state-machine/src/overlayed_changes/mod.rs
index ef5c02d2ec1..9eb26d52f79 100644
--- a/substrate/primitives/state-machine/src/overlayed_changes/mod.rs
+++ b/substrate/primitives/state-machine/src/overlayed_changes/mod.rs
@@ -474,7 +474,7 @@ impl OverlayedChanges {
 	pub fn children(
 		&self,
 	) -> impl Iterator<Item = (impl Iterator<Item = (&StorageKey, &OverlayedValue)>, &ChildInfo)> {
-		self.children.iter().map(|(_, v)| (v.0.changes(), &v.1))
+		self.children.values().map(|v| (v.0.changes(), &v.1))
 	}
 
 	/// Get an iterator over all top changes as been by the current transaction.
diff --git a/substrate/primitives/trie/src/recorder.rs b/substrate/primitives/trie/src/recorder.rs
index 5599ad1c369..6fbf698592a 100644
--- a/substrate/primitives/trie/src/recorder.rs
+++ b/substrate/primitives/trie/src/recorder.rs
@@ -109,7 +109,7 @@ impl<H: Hasher> Recorder<H> {
 	/// Returns the [`StorageProof`].
 	pub fn to_storage_proof(&self) -> StorageProof {
 		let recorder = self.inner.lock();
-		StorageProof::new(recorder.accessed_nodes.iter().map(|(_, v)| v.clone()))
+		StorageProof::new(recorder.accessed_nodes.values().cloned())
 	}
 
 	/// Returns the estimated encoded size of the proof.
diff --git a/substrate/test-utils/runtime/client/src/lib.rs b/substrate/test-utils/runtime/client/src/lib.rs
index fe0fef35166..99d4e1163e2 100644
--- a/substrate/test-utils/runtime/client/src/lib.rs
+++ b/substrate/test-utils/runtime/client/src/lib.rs
@@ -134,7 +134,7 @@ impl substrate_test_client::GenesisInit for GenesisParameters {
 				.insert(sp_core::storage::well_known_keys::CODE.to_vec(), code.clone());
 		}
 
-		let child_roots = storage.children_default.iter().map(|(_sk, child_content)| {
+		let child_roots = storage.children_default.values().map(|child_content| {
 			let state_root =
 				<<<runtime::Block as BlockT>::Header as HeaderT>::Hashing as HashT>::trie_root(
 					child_content.data.clone().into_iter().collect(),
diff --git a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
index daf4aa74e13..6e413bdf7e2 100644
--- a/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
+++ b/substrate/utils/frame/benchmarking-cli/src/pallet/command.rs
@@ -268,9 +268,8 @@ impl PalletCmd {
 
 					for s in 0..self.steps {
 						// This is the value we will be testing for component `name`
-						let component_value = ((lowest as f32 + step_size * s as f32) as u32)
-							.min(highest)
-							.max(lowest);
+						let component_value =
+							((lowest as f32 + step_size * s as f32) as u32).clamp(lowest, highest);
 
 						// Select the max value for all the other components.
 						let c: Vec<(BenchmarkParameter, u32)> = components
-- 
GitLab