From ccff9a08f049158f11717132b998358c2af7b5b4 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 24 Jan 2026 04:13:49 +0100 Subject: [PATCH] chore: fix clippy unnecessary_sort_by lint (#21385) --- crates/era-downloader/src/fs.rs | 2 +- crates/net/discv4/src/lib.rs | 2 +- crates/stages/stages/src/stages/hashing_account.rs | 2 +- crates/trie/common/src/updates.rs | 8 ++++---- crates/trie/trie/src/hashed_cursor/post_state.rs | 4 ++-- crates/trie/trie/src/trie_cursor/in_memory.rs | 4 ++-- crates/trie/trie/src/verify.rs | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/era-downloader/src/fs.rs b/crates/era-downloader/src/fs.rs index eaab1f3f4b..f504fdd269 100644 --- a/crates/era-downloader/src/fs.rs +++ b/crates/era-downloader/src/fs.rs @@ -52,7 +52,7 @@ pub fn read_dir( checksums.next().transpose()?.ok_or_eyre("Got less checksums than ERA files")?; } - entries.sort_by(|(left, _), (right, _)| left.cmp(right)); + entries.sort_by_key(|(left, _)| *left); Ok(stream::iter(entries.into_iter().skip_while(move |(n, _)| *n < start_index).map( move |(_, path)| { diff --git a/crates/net/discv4/src/lib.rs b/crates/net/discv4/src/lib.rs index 0255dac1a7..4ce240ed2f 100644 --- a/crates/net/discv4/src/lib.rs +++ b/crates/net/discv4/src/lib.rs @@ -1631,7 +1631,7 @@ impl Discv4Service { .filter(|entry| entry.node.value.is_expired()) .map(|n| n.node.value) .collect::>(); - nodes.sort_by(|a, b| a.last_seen.cmp(&b.last_seen)); + nodes.sort_by_key(|a| a.last_seen); let to_ping = nodes.into_iter().map(|n| n.record).take(MAX_NODES_PING).collect::>(); for node in to_ping { self.try_ping(node, PingReason::RePing) diff --git a/crates/stages/stages/src/stages/hashing_account.rs b/crates/stages/stages/src/stages/hashing_account.rs index d9e5c9e2c3..f38b638405 100644 --- a/crates/stages/stages/src/stages/hashing_account.rs +++ b/crates/stages/stages/src/stages/hashing_account.rs @@ -99,7 +99,7 @@ impl AccountHashingStage { // Account State generator let mut account_cursor = provider.tx_ref().cursor_write::()?; - accounts.sort_by(|a, b| a.0.cmp(&b.0)); + accounts.sort_by_key(|a| a.0); for (addr, acc) in &accounts { account_cursor.append(*addr, acc)?; } diff --git a/crates/trie/common/src/updates.rs b/crates/trie/common/src/updates.rs index 2698510808..255979df9d 100644 --- a/crates/trie/common/src/updates.rs +++ b/crates/trie/common/src/updates.rs @@ -169,7 +169,7 @@ impl TrieUpdates { .collect::>(); account_nodes.extend(self.removed_nodes.drain().map(|path| (path, None))); - account_nodes.sort_unstable_by(|a, b| a.0.cmp(&b.0)); + account_nodes.sort_unstable_by_key(|a| a.0); let storage_tries = self .storage_tries @@ -195,7 +195,7 @@ impl TrieUpdates { .filter(|path| !self.account_nodes.contains_key(*path)) .map(|path| (*path, None)), ); - account_nodes.sort_unstable_by(|a, b| a.0.cmp(&b.0)); + account_nodes.sort_unstable_by_key(|a| a.0); let storage_tries = self .storage_tries @@ -373,7 +373,7 @@ impl StorageTrieUpdates { .collect::>(); storage_nodes.extend(self.removed_nodes.into_iter().map(|path| (path, None))); - storage_nodes.sort_unstable_by(|a, b| a.0.cmp(&b.0)); + storage_nodes.sort_unstable_by_key(|a| a.0); StorageTrieUpdatesSorted { is_deleted: self.is_deleted, storage_nodes } } @@ -394,7 +394,7 @@ impl StorageTrieUpdates { .filter(|path| !self.storage_nodes.contains_key(*path)) .map(|path| (*path, None)), ); - storage_nodes.sort_unstable_by(|a, b| a.0.cmp(&b.0)); + storage_nodes.sort_unstable_by_key(|a| a.0); StorageTrieUpdatesSorted { is_deleted: self.is_deleted, storage_nodes } } diff --git a/crates/trie/trie/src/hashed_cursor/post_state.rs b/crates/trie/trie/src/hashed_cursor/post_state.rs index fe2c6b9e0c..7436e46694 100644 --- a/crates/trie/trie/src/hashed_cursor/post_state.rs +++ b/crates/trie/trie/src/hashed_cursor/post_state.rs @@ -420,7 +420,7 @@ mod tests { .into_iter() .map(|(byte, value)| (B256::repeat_byte(byte), value)) .collect(); - result.sort_by(|a, b| a.0.cmp(&b.0)); + result.sort_by_key(|a| a.0); result.dedup_by(|a, b| a.0 == b.0); result }) @@ -438,7 +438,7 @@ mod tests { (B256::repeat_byte(byte), effective_value) }) .collect(); - result.sort_by(|a, b| a.0.cmp(&b.0)); + result.sort_by_key(|a| a.0); result.dedup_by(|a, b| a.0 == b.0); result }, diff --git a/crates/trie/trie/src/trie_cursor/in_memory.rs b/crates/trie/trie/src/trie_cursor/in_memory.rs index 941fbf9633..cfde967409 100644 --- a/crates/trie/trie/src/trie_cursor/in_memory.rs +++ b/crates/trie/trie/src/trie_cursor/in_memory.rs @@ -758,7 +758,7 @@ mod tests { .into_iter() .map(|(bytes, node)| (Nibbles::from_nibbles_unchecked(bytes), node)) .collect(); - result.sort_by(|a, b| a.0.cmp(&b.0)); + result.sort_by_key(|a| a.0); result.dedup_by(|a, b| a.0 == b.0); result }) @@ -780,7 +780,7 @@ mod tests { .into_iter() .map(|(bytes, node)| (Nibbles::from_nibbles_unchecked(bytes), node)) .collect(); - result.sort_by(|a, b| a.0.cmp(&b.0)); + result.sort_by_key(|a| a.0); result.dedup_by(|a, b| a.0 == b.0); result }) diff --git a/crates/trie/trie/src/verify.rs b/crates/trie/trie/src/verify.rs index ce17dc30d4..fc371058ce 100644 --- a/crates/trie/trie/src/verify.rs +++ b/crates/trie/trie/src/verify.rs @@ -13,7 +13,7 @@ use alloy_primitives::B256; use alloy_trie::BranchNodeCompact; use reth_execution_errors::StateRootError; use reth_storage_errors::db::DatabaseError; -use std::cmp::Ordering; +use std::cmp::{Ordering, Reverse}; use tracing::trace; /// Used by [`StateRootBranchNodesIter`] to iterate over branch nodes in a state root. @@ -141,7 +141,7 @@ impl Iterator for StateRootBranchNodesIter { // By sorting by the account we ensure that we continue with the partially processed // trie (the last of the previous run) first. We sort in reverse order because we pop // off of this Vec. - self.storage_tries.sort_unstable_by(|a, b| b.0.cmp(&a.0)); + self.storage_tries.sort_unstable_by_key(|a| Reverse(a.0)); // loop back to the top. }