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
@@ -60,8 +60,13 @@ fn main() {
let expected = ue.unwrap() + ve.unwrap();
let t = u.clone().add(&v);
assert_eq!(
u128::try_from(t.clone()).unwrap(), expected,
"{:?} + {:?} ===> {:?} != {:?}", u, v, t, expected,
u128::try_from(t.clone()).unwrap(),
expected,
"{:?} + {:?} ===> {:?} != {:?}",
u,
v,
t,
expected,
);
}
@@ -74,8 +79,13 @@ fn main() {
let t = t.unwrap();
let expected = expected.unwrap();
assert_eq!(
u128::try_from(t.clone()).unwrap(), expected,
"{:?} - {:?} ===> {:?} != {:?}", u, v, t, expected,
u128::try_from(t.clone()).unwrap(),
expected,
"{:?} - {:?} ===> {:?} != {:?}",
u,
v,
t,
expected,
);
}
}
@@ -84,31 +94,51 @@ fn main() {
let expected = ue.unwrap() * ve.unwrap();
let t = u.clone().mul(&v);
assert_eq!(
u128::try_from(t.clone()).unwrap(), expected,
"{:?} * {:?} ===> {:?} != {:?}", u, v, t, expected,
u128::try_from(t.clone()).unwrap(),
expected,
"{:?} * {:?} ===> {:?} != {:?}",
u,
v,
t,
expected,
);
}
if check_digit_lengths(&u, &v, 4) {
let (ue, ve) = (ue.unwrap(), ve.unwrap());
if ve == 0 {
return;
return
}
let (q, r) = (ue / ve, ue % ve);
if let Some((qq, rr)) = u.clone().div(&v, true) {
assert_eq!(
u128::try_from(qq.clone()).unwrap(), q,
"{:?} / {:?} ===> {:?} != {:?}", u, v, qq, q,
u128::try_from(qq.clone()).unwrap(),
q,
"{:?} / {:?} ===> {:?} != {:?}",
u,
v,
qq,
q,
);
assert_eq!(
u128::try_from(rr.clone()).unwrap(), r,
"{:?} % {:?} ===> {:?} != {:?}", u, v, rr, r,
u128::try_from(rr.clone()).unwrap(),
r,
"{:?} % {:?} ===> {:?} != {:?}",
u,
v,
rr,
r,
);
} else if v.len() == 1 {
let qq = u.clone().div_unit(ve as Single);
assert_eq!(
u128::try_from(qq.clone()).unwrap(), q,
"[single] {:?} / {:?} ===> {:?} != {:?}", u, v, qq, q,
u128::try_from(qq.clone()).unwrap(),
q,
"[single] {:?} / {:?} ===> {:?} != {:?}",
u,
v,
qq,
q,
);
} else if v.msb() != 0 && u.msb() != 0 && u.len() > v.len() {
panic!("div returned none for an unexpected reason");
@@ -175,7 +205,7 @@ fn assert_biguints_eq(a: &BigUint, b: &num_bigint::BigUint) {
// `num_bigint::BigUint` doesn't expose it's internals, so we need to convert into that to
// compare.
let limbs = (0 .. a.len()).map(|i| a.get(i)).collect();
let limbs = (0..a.len()).map(|i| a.get(i)).collect();
let num_a = num_bigint::BigUint::new(limbs);
assert!(&num_a == b, "\narithmetic: {:?}\nnum-bigint: {:?}", a, b);
@@ -28,7 +28,7 @@
//! [here](https://docs.rs/honggfuzz/).
use honggfuzz::fuzz;
use sp_arithmetic::{FixedPointNumber, FixedI64, traits::Saturating};
use sp_arithmetic::{traits::Saturating, FixedI64, FixedPointNumber};
fn main() {
loop {
@@ -38,7 +38,8 @@ fn main() {
// Check `from_rational` and division are consistent.
if y != 0 {
let f1 = FixedI64::saturating_from_integer(x) / FixedI64::saturating_from_integer(y);
let f1 =
FixedI64::saturating_from_integer(x) / FixedI64::saturating_from_integer(y);
let f2 = FixedI64::saturating_from_rational(x, y);
assert_eq!(f1.into_inner(), f2.into_inner());
}
@@ -75,7 +76,8 @@ fn main() {
let a = FixedI64::saturating_from_rational(2, 5);
let b = a.saturating_mul_acc_int(x);
let xx = FixedI64::saturating_from_integer(x);
let d = a.saturating_mul(xx).saturating_add(xx).into_inner() as i128 / FixedI64::accuracy() as i128;
let d = a.saturating_mul(xx).saturating_add(xx).into_inner() as i128 /
FixedI64::accuracy() as i128;
assert_eq!(b, d);
});
}
@@ -60,7 +60,7 @@ fn main() {
fn mul_div(a: u128, b: u128, c: u128) -> u128 {
use primitive_types::U256;
if a.is_zero() {
return Zero::zero();
return Zero::zero()
}
let c = c.max(1);
@@ -15,7 +15,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//! # Running
//! Running this fuzzer can be done with `cargo hfuzz run normalize`. `honggfuzz` CLI options can
//! be used by setting `HFUZZ_RUN_ARGS`, such as `-n 4` to use 4 threads.
@@ -37,7 +36,9 @@ fn main() {
loop {
fuzz!(|data: (Vec<Ty>, Ty)| {
let (data, norm) = data;
if data.len() == 0 { return; }
if data.len() == 0 {
return
}
let pre_sum: u128 = data.iter().map(|x| *x as u128).sum();
let normalized = data.normalize(norm);
@@ -50,13 +51,7 @@ fn main() {
let sum: u128 = normalized.iter().map(|x| *x as u128).sum();
// if this function returns Ok(), then it will ALWAYS be accurate.
assert_eq!(
sum,
norm as u128,
"sums don't match {:?}, {}",
normalized,
norm,
);
assert_eq!(sum, norm as u128, "sums don't match {:?}, {}", normalized, norm,);
} else {
panic!("Should have returned Ok for input = {:?}, target = {:?}", data, norm);
}
@@ -24,16 +24,11 @@
//! `cargo hfuzz run-debug per_thing_rational hfuzz_workspace/per_thing_rational/*.fuzz`.
use honggfuzz::fuzz;
use sp_arithmetic::{
PerThing, PerU16, Percent, Perbill, Perquintill, traits::SaturatedConversion,
};
use sp_arithmetic::{traits::SaturatedConversion, PerThing, PerU16, Perbill, Percent, Perquintill};
fn main() {
loop {
fuzz!(|
data: ((u16, u16), (u32, u32), (u64, u64))
| {
fuzz!(|data: ((u16, u16), (u32, u32), (u64, u64))| {
let (u16_pair, u32_pair, u64_pair) = data;
// peru16
@@ -109,7 +104,6 @@ fn main() {
Perquintill::from_float(smaller as f64 / bigger.max(1) as f64),
1000,
);
})
}
}