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
@@ -21,7 +21,7 @@
#![warn(missing_docs)]
use frame_support::RuntimeDebug;
use sp_runtime::traits::{self, Saturating, One};
use sp_runtime::traits::{self, One, Saturating};
use sp_std::fmt;
#[cfg(not(feature = "std"))]
use sp_std::prelude::Vec;
@@ -55,16 +55,10 @@ impl LeafDataProvider for () {
/// current block hash is not available (since the block is not finished yet),
/// we use the `parent_hash` here along with parent block number.
impl<T: frame_system::Config> LeafDataProvider for frame_system::Pallet<T> {
type LeafData = (
<T as frame_system::Config>::BlockNumber,
<T as frame_system::Config>::Hash
);
type LeafData = (<T as frame_system::Config>::BlockNumber, <T as frame_system::Config>::Hash);
fn leaf_data() -> Self::LeafData {
(
Self::block_number().saturating_sub(One::one()),
Self::parent_hash()
)
(Self::block_number().saturating_sub(One::one()), Self::parent_hash())
}
}
@@ -130,7 +124,8 @@ mod encoding {
fn encode_to<T: codec::Output + ?Sized>(&self, dest: &mut T) {
match self {
Self::Data(l) => l.using_encoded(
|data| Either::<&[u8], &H::Output>::Left(data).encode_to(dest), false
|data| Either::<&[u8], &H::Output>::Left(data).encode_to(dest),
false,
),
Self::Hash(h) => Either::<&[u8], &H::Output>::Right(h).encode_to(dest),
}
@@ -258,7 +253,8 @@ macro_rules! impl_leaf_data_for_tuple {
/// Test functions implementation for `Compact<H, (DataOrHash<H, Tuple>, ...)>`
#[cfg(test)]
impl<H, A, B> Compact<H, (DataOrHash<H, A>, DataOrHash<H, B>)> where
impl<H, A, B> Compact<H, (DataOrHash<H, A>, DataOrHash<H, B>)>
where
H: traits::Hash,
A: FullLeaf,
B: FullLeaf,
@@ -346,7 +342,7 @@ pub struct OpaqueLeaf(
///
/// NOTE it DOES NOT include length prefix (like `Vec<u8>` encoding would).
#[cfg_attr(feature = "std", serde(with = "sp_core::bytes"))]
pub Vec<u8>
pub Vec<u8>,
);
impl OpaqueLeaf {
@@ -474,25 +470,21 @@ mod tests {
];
// when
let encoded = cases
.iter()
.map(codec::Encode::encode)
.collect::<Vec<_>>();
let encoded = cases.iter().map(codec::Encode::encode).collect::<Vec<_>>();
let decoded = encoded
.iter()
.map(|x| Test::decode(&mut &**x))
.collect::<Vec<_>>();
let decoded = encoded.iter().map(|x| Test::decode(&mut &**x)).collect::<Vec<_>>();
// then
assert_eq!(decoded, cases.into_iter().map(Result::<_, codec::Error>::Ok).collect::<Vec<_>>());
assert_eq!(
decoded,
cases.into_iter().map(Result::<_, codec::Error>::Ok).collect::<Vec<_>>()
);
// check encoding correctness
assert_eq!(&encoded[0], &hex_literal::hex!("00343048656c6c6f20576f726c6421"));
assert_eq!(
encoded[1].as_slice(),
hex_literal::hex!(
"01c3e7ba6b511162fead58f2c8b5764ce869ed1118011ac37392522ed16720bbcd"
).as_ref()
hex_literal::hex!("01c3e7ba6b511162fead58f2c8b5764ce869ed1118011ac37392522ed16720bbcd")
.as_ref()
);
}
@@ -519,10 +511,7 @@ mod tests {
// when
let c: TestCompact = Compact::new((a.clone(), b.clone()));
let d: TestCompact = Compact::new((
Test::Hash(a.hash()),
Test::Hash(b.hash()),
));
let d: TestCompact = Compact::new((Test::Hash(a.hash()), Test::Hash(b.hash())));
// then
assert_eq!(c.hash(), d.hash());
@@ -535,35 +524,28 @@ mod tests {
let b = Test::Data("".into());
let c: TestCompact = Compact::new((a.clone(), b.clone()));
let d: TestCompact = Compact::new((
Test::Hash(a.hash()),
Test::Hash(b.hash()),
));
let d: TestCompact = Compact::new((Test::Hash(a.hash()), Test::Hash(b.hash())));
let cases = vec![c, d.clone()];
// when
let encoded_compact = cases
.iter()
.map(|c| c.using_encoded(|x| x.to_vec(), true))
.collect::<Vec<_>>();
let encoded_compact =
cases.iter().map(|c| c.using_encoded(|x| x.to_vec(), true)).collect::<Vec<_>>();
let encoded = cases
.iter()
.map(|c| c.using_encoded(|x| x.to_vec(), false))
.collect::<Vec<_>>();
let encoded =
cases.iter().map(|c| c.using_encoded(|x| x.to_vec(), false)).collect::<Vec<_>>();
let decoded_compact = encoded_compact
.iter()
.map(|x| TestCompact::decode(&mut &**x))
.collect::<Vec<_>>();
let decoded = encoded
.iter()
.map(|x| TestCompact::decode(&mut &**x))
.collect::<Vec<_>>();
let decoded = encoded.iter().map(|x| TestCompact::decode(&mut &**x)).collect::<Vec<_>>();
// then
assert_eq!(decoded, cases.into_iter().map(Result::<_, codec::Error>::Ok).collect::<Vec<_>>());
assert_eq!(
decoded,
cases.into_iter().map(Result::<_, codec::Error>::Ok).collect::<Vec<_>>()
);
assert_eq!(decoded_compact, vec![Ok(d.clone()), Ok(d.clone())]);
}
@@ -575,10 +557,7 @@ mod tests {
let b = Test::Data("".into());
let c: TestCompact = Compact::new((a.clone(), b.clone()));
let d: TestCompact = Compact::new((
Test::Hash(a.hash()),
Test::Hash(b.hash()),
));
let d: TestCompact = Compact::new((Test::Hash(a.hash()), Test::Hash(b.hash())));
let cases = vec![c, d.clone()];
let encoded_compact = cases
@@ -587,16 +566,10 @@ mod tests {
.map(OpaqueLeaf::from_encoded_leaf)
.collect::<Vec<_>>();
let opaque = cases
.iter()
.map(OpaqueLeaf::from_leaf)
.collect::<Vec<_>>();
let opaque = cases.iter().map(OpaqueLeaf::from_leaf).collect::<Vec<_>>();
// then
assert_eq!(
encoded_compact,
opaque,
);
assert_eq!(encoded_compact, opaque,);
}
#[test]
@@ -610,10 +583,7 @@ mod tests {
let case3 = a.encode().encode();
// when
let encoded = vec![&case1, &case2]
.into_iter()
.map(|x| x.encode())
.collect::<Vec<_>>();
let encoded = vec![&case1, &case2].into_iter().map(|x| x.encode()).collect::<Vec<_>>();
let decoded = vec![&*encoded[0], &*encoded[1], &*case3]
.into_iter()
.map(|x| EncodableOpaqueLeaf::decode(&mut &*x))