Run cargo fmt on the whole code base (#9394)

* Run cargo fmt on the whole code base

* Second run

* Add CI check

* Fix compilation

* More unnecessary braces

* Handle weights

* Use --all

* Use correct attributes...

* Fix UI tests

* AHHHHHHHHH

* 🤦

* Docs

* Fix compilation

* 🤷

* Please stop

* 🤦 x 2

* More

* make rustfmt.toml consistent with polkadot

Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
@@ -164,13 +164,13 @@
#![cfg_attr(not(feature = "std"), no_std)]
pub mod onchain;
use sp_std::{prelude::*, fmt::Debug};
use frame_support::weights::Weight;
use sp_std::{fmt::Debug, prelude::*};
/// Re-export some type as they are used in the interface.
pub use sp_arithmetic::PerThing;
pub use sp_npos_elections::{
Assignment, ExtendedBalance, PerThing128, Supports, Support, VoteWeight
Assignment, ExtendedBalance, PerThing128, Support, Supports, VoteWeight,
};
/// Types that are used by the data provider trait.
@@ -224,7 +224,8 @@ pub trait ElectionDataProvider<AccountId, BlockNumber> {
_voters: Vec<(AccountId, VoteWeight, Vec<AccountId>)>,
_targets: Vec<AccountId>,
_target_stake: Option<VoteWeight>,
) {}
) {
}
/// Utility function only to be used in benchmarking scenarios, to be implemented optionally,
/// else a noop.
@@ -18,9 +18,9 @@
//! An implementation of [`ElectionProvider`] that does an on-chain sequential phragmen.
use crate::{ElectionDataProvider, ElectionProvider};
use frame_support::{traits::Get, weights::Weight};
use sp_npos_elections::*;
use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData, prelude::*};
use frame_support::{traits::Get, weights::Weight};
/// Errors of the on-chain election.
#[derive(Eq, PartialEq, Debug)]
@@ -83,9 +83,8 @@ impl<T: Config> ElectionProvider<T::AccountId, T::BlockNumber> for OnChainSequen
stake_map.insert(v.clone(), *s);
});
let stake_of = |w: &T::AccountId| -> VoteWeight {
stake_map.get(w).cloned().unwrap_or_default()
};
let stake_of =
|w: &T::AccountId| -> VoteWeight { stake_map.get(w).cloned().unwrap_or_default() };
let ElectionResult { winners, assignments } =
seq_phragmen::<_, T::Accuracy>(desired_targets as usize, targets, voters, None)
@@ -94,16 +93,18 @@ impl<T: Config> ElectionProvider<T::AccountId, T::BlockNumber> for OnChainSequen
let staked = assignment_ratio_to_staked_normalized(assignments, &stake_of)?;
let winners = to_without_backing(winners);
to_supports(&winners, &staked).map_err(Error::from).map(|s| (s, T::BlockWeights::get().max_block))
to_supports(&winners, &staked)
.map_err(Error::from)
.map(|s| (s, T::BlockWeights::get().max_block))
}
}
#[cfg(test)]
mod tests {
use super::*;
use frame_support::weights::Weight;
use sp_npos_elections::Support;
use sp_runtime::Perbill;
use frame_support::weights::Weight;
type AccountId = u64;
type BlockNumber = u32;
@@ -151,20 +152,8 @@ mod tests {
assert_eq!(
OnChainPhragmen::elect().unwrap().0,
vec![
(
10,
Support {
total: 25,
voters: vec![(1, 10), (3, 15)]
}
),
(
30,
Support {
total: 35,
voters: vec![(2, 20), (3, 15)]
}
)
(10, Support { total: 25, voters: vec![(1, 10), (3, 15)] }),
(30, Support { total: 35, voters: vec![(2, 20), (3, 15)] })
]
);
}