Apply some clippy lints (#11154)

* Apply some clippy hints

* Revert clippy ci changes

* Update client/cli/src/commands/generate.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/cli/src/commands/inspect_key.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/db/src/bench.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/service/src/client/block_rules.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/transactions.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/network/src/protocol.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Revert due to missing `or_default` function.

* Fix compilation and simplify code

* Undo change that corrupts benchmark.

* fix clippy

* Update client/service/test/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update client/state-db/src/noncanonical.rs

remove leftovers!

* Update client/tracing/src/logging/directives.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/fork-tree/src/lib.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* added needed ref

* Update frame/referenda/src/benchmarking.rs

* Simplify byte-vec creation

* let's just not overlap the ranges

* Correction

* cargo fmt

* Update utils/frame/benchmarking-cli/src/shared/stats.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update utils/frame/benchmarking-cli/src/pallet/command.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
Falco Hirschenberger
2022-04-30 23:28:27 +02:00
committed by GitHub
parent a990473cf9
commit b581604aa7
368 changed files with 1927 additions and 2236 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ fn main() {
match action {
Action::Insert => {
if BagsList::on_insert(id.clone(), vote_weight).is_err() {
if BagsList::on_insert(id, vote_weight).is_err() {
// this was a duplicate id, which is ok. We can just update it.
BagsList::on_update(&id, vote_weight);
}
@@ -21,7 +21,7 @@ use frame_election_provider_support::ScoreProvider;
use sp_std::prelude::*;
/// A common log target to use.
pub const LOG_TARGET: &'static str = "runtime::bags-list::remote-tests";
pub const LOG_TARGET: &str = "runtime::bags-list::remote-tests";
pub mod migration;
pub mod sanity_check;
+1 -1
View File
@@ -133,7 +133,7 @@ frame_benchmarking::benchmarks! {
List::<T, _>::get_bags(),
vec![
(origin_bag_thresh, vec![origin_head.clone()]),
(dest_bag_thresh, vec![dest_head.clone(), origin_tail.clone()])
(dest_bag_thresh, vec![dest_head.clone(), origin_tail])
]
);
}
+2 -2
View File
@@ -74,7 +74,7 @@ pub use list::{notional_bag_for, Bag, List, ListError, Node};
pub use pallet::*;
pub use weights::WeightInfo;
pub(crate) const LOG_TARGET: &'static str = "runtime::bags_list";
pub(crate) const LOG_TARGET: &str = "runtime::bags_list";
// syntactic sugar for logging.
#[macro_export]
@@ -254,7 +254,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
pub fn do_rebag(account: &T::AccountId, new_weight: T::Score) -> Option<(T::Score, T::Score)> {
// if no voter at that node, don't do anything.
// the caller just wasted the fee to call this.
let maybe_movement = list::Node::<T, I>::get(&account)
let maybe_movement = list::Node::<T, I>::get(account)
.and_then(|node| List::update_position_for(node, new_weight));
if let Some((from, to)) = maybe_movement {
Self::deposit_event(Event::<T, I>::Rebagged { who: account.clone(), from, to });
+9 -9
View File
@@ -59,7 +59,7 @@ mod tests;
pub fn notional_bag_for<T: Config<I>, I: 'static>(score: T::Score) -> T::Score {
let thresholds = T::BagThresholds::get();
let idx = thresholds.partition_point(|&threshold| score > threshold);
thresholds.get(idx).copied().unwrap_or(T::Score::max_value())
thresholds.get(idx).copied().unwrap_or_else(T::Score::max_value)
}
/// The **ONLY** entry point of this module. All operations to the bags-list should happen through
@@ -163,7 +163,7 @@ impl<T: Config<I>, I: 'static> List<T, I> {
let affected_bag = {
// this recreates `notional_bag_for` logic, but with the old thresholds.
let idx = old_thresholds.partition_point(|&threshold| inserted_bag > threshold);
old_thresholds.get(idx).copied().unwrap_or(T::Score::max_value())
old_thresholds.get(idx).copied().unwrap_or_else(T::Score::max_value)
};
if !affected_old_bags.insert(affected_bag) {
// If the previous threshold list was [10, 20], and we insert [3, 5], then there's
@@ -420,24 +420,24 @@ impl<T: Config<I>, I: 'static> List<T, I> {
use crate::pallet;
use frame_support::ensure;
let lighter_node = Node::<T, I>::get(&lighter_id).ok_or(pallet::Error::IdNotFound)?;
let heavier_node = Node::<T, I>::get(&heavier_id).ok_or(pallet::Error::IdNotFound)?;
let lighter_node = Node::<T, I>::get(lighter_id).ok_or(pallet::Error::IdNotFound)?;
let heavier_node = Node::<T, I>::get(heavier_id).ok_or(pallet::Error::IdNotFound)?;
ensure!(lighter_node.bag_upper == heavier_node.bag_upper, pallet::Error::NotInSameBag);
// this is the most expensive check, so we do it last.
ensure!(
T::ScoreProvider::score(&heavier_id) > T::ScoreProvider::score(&lighter_id),
T::ScoreProvider::score(heavier_id) > T::ScoreProvider::score(lighter_id),
pallet::Error::NotHeavier
);
// remove the heavier node from this list. Note that this removes the node from storage and
// decrements the node counter.
Self::remove(&heavier_id);
Self::remove(heavier_id);
// re-fetch `lighter_node` from storage since it may have been updated when `heavier_node`
// was removed.
let lighter_node = Node::<T, I>::get(&lighter_id).ok_or_else(|| {
let lighter_node = Node::<T, I>::get(lighter_id).ok_or_else(|| {
debug_assert!(false, "id that should exist cannot be found");
crate::log!(warn, "id that should exist cannot be found");
pallet::Error::IdNotFound
@@ -527,7 +527,7 @@ impl<T: Config<I>, I: 'static> List<T, I> {
thresholds.into_iter().filter_map(|t| Bag::<T, I>::get(t))
};
let _ = active_bags.clone().map(|b| b.sanity_check()).collect::<Result<_, _>>()?;
let _ = active_bags.clone().try_for_each(|b| b.sanity_check())?;
let nodes_in_bags_count =
active_bags.clone().fold(0u32, |acc, cur| acc + cur.iter().count() as u32);
@@ -708,7 +708,7 @@ impl<T: Config<I>, I: 'static> Bag<T, I> {
// the first insertion into the bag. In this case, both head and tail should point to the
// same node.
if self.head.is_none() {
self.head = Some(id.clone());
self.head = Some(id);
debug_assert!(self.iter().count() == 1);
}
}
+1 -1
View File
@@ -42,7 +42,7 @@ impl frame_election_provider_support::ScoreProvider<AccountId> for StakingMock {
#[cfg(any(feature = "runtime-benchmarks", test))]
fn set_score_of(id: &AccountId, weight: Self::Score) {
NEXT_VOTE_WEIGHT_MAP.with(|m| m.borrow_mut().insert(id.clone(), weight));
NEXT_VOTE_WEIGHT_MAP.with(|m| m.borrow_mut().insert(*id, weight));
}
}