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
+2 -2
View File
@@ -101,7 +101,7 @@ impl StorageHasher for Twox64Concat {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Twox64Concat;
type Output = Vec<u8>;
fn hash(x: &[u8]) -> Vec<u8> {
twox_64(x).iter().chain(x.into_iter()).cloned().collect::<Vec<_>>()
twox_64(x).iter().chain(x.iter()).cloned().collect::<Vec<_>>()
}
fn max_len<K: MaxEncodedLen>() -> usize {
K::max_encoded_len().saturating_add(8)
@@ -123,7 +123,7 @@ impl StorageHasher for Blake2_128Concat {
const METADATA: metadata::StorageHasher = metadata::StorageHasher::Blake2_128Concat;
type Output = Vec<u8>;
fn hash(x: &[u8]) -> Vec<u8> {
blake2_128(x).iter().chain(x.into_iter()).cloned().collect::<Vec<_>>()
blake2_128(x).iter().chain(x.iter()).cloned().collect::<Vec<_>>()
}
fn max_len<K: MaxEncodedLen>() -> usize {
K::max_encoded_len().saturating_add(16)
+1 -1
View File
@@ -105,7 +105,7 @@ use scale_info::TypeInfo;
use sp_runtime::TypeId;
/// A unified log target for support operations.
pub const LOG_TARGET: &'static str = "runtime::frame-support";
pub const LOG_TARGET: &str = "runtime::frame-support";
/// A type that cannot be instantiated.
#[derive(Encode, Decode, Debug, PartialEq, Eq, Clone, TypeInfo)]
+2 -2
View File
@@ -50,7 +50,7 @@ pub fn get<T: Decode + Sized>(child_info: &ChildInfo, key: &[u8]) -> Option<T> {
/// Return the value of the item in storage under `key`, or the type's default if there is no
/// explicit entry.
pub fn get_or_default<T: Decode + Sized + Default>(child_info: &ChildInfo, key: &[u8]) -> T {
get(child_info, key).unwrap_or_else(Default::default)
get(child_info, key).unwrap_or_default()
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
@@ -90,7 +90,7 @@ pub fn take<T: Decode + Sized>(child_info: &ChildInfo, key: &[u8]) -> Option<T>
/// Remove `key` from storage, returning its value, or, if there was no explicit entry in storage,
/// the default for its type.
pub fn take_or_default<T: Codec + Sized + Default>(child_info: &ChildInfo, key: &[u8]) -> T {
take(child_info, key).unwrap_or_else(Default::default)
take(child_info, key).unwrap_or_default()
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
@@ -461,7 +461,7 @@ where
},
};
let mut key2_material = G::Hasher2::reverse(&key_material);
let mut key2_material = G::Hasher2::reverse(key_material);
let key2 = match K2::decode(&mut key2_material) {
Ok(key2) => key2,
Err(_) => {
+13 -13
View File
@@ -28,7 +28,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::get(&hash(key).as_ref())
unhashed::get(hash(key).as_ref())
}
/// Return the value of the item in storage under `key`, or the type's default if there is no
@@ -39,7 +39,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::get_or_default(&hash(key).as_ref())
unhashed::get_or_default(hash(key).as_ref())
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
@@ -50,7 +50,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::get_or(&hash(key).as_ref(), default_value)
unhashed::get_or(hash(key).as_ref(), default_value)
}
/// Return the value of the item in storage under `key`, or `default_value()` if there is no
@@ -62,7 +62,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::get_or_else(&hash(key).as_ref(), default_value)
unhashed::get_or_else(hash(key).as_ref(), default_value)
}
/// Put `value` in storage under `key`.
@@ -72,7 +72,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::put(&hash(key).as_ref(), value)
unhashed::put(hash(key).as_ref(), value)
}
/// Remove `key` from storage, returning its value if it had an explicit entry or `None` otherwise.
@@ -82,7 +82,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::take(&hash(key).as_ref())
unhashed::take(hash(key).as_ref())
}
/// Remove `key` from storage, returning its value, or, if there was no explicit entry in storage,
@@ -93,7 +93,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::take_or_default(&hash(key).as_ref())
unhashed::take_or_default(hash(key).as_ref())
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
@@ -104,7 +104,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::take_or(&hash(key).as_ref(), default_value)
unhashed::take_or(hash(key).as_ref(), default_value)
}
/// Return the value of the item in storage under `key`, or `default_value()` if there is no
@@ -116,7 +116,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::take_or_else(&hash(key).as_ref(), default_value)
unhashed::take_or_else(hash(key).as_ref(), default_value)
}
/// Check to see if `key` has an explicit entry in storage.
@@ -125,7 +125,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::exists(&hash(key).as_ref())
unhashed::exists(hash(key).as_ref())
}
/// Ensure `key` has no explicit entry in storage.
@@ -134,7 +134,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::kill(&hash(key).as_ref())
unhashed::kill(hash(key).as_ref())
}
/// Get a Vec of bytes from storage.
@@ -143,7 +143,7 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::get_raw(&hash(key).as_ref())
unhashed::get_raw(hash(key).as_ref())
}
/// Put a raw byte slice into storage.
@@ -152,5 +152,5 @@ where
HashFn: Fn(&[u8]) -> R,
R: AsRef<[u8]>,
{
unhashed::put_raw(&hash(key).as_ref(), value)
unhashed::put_raw(hash(key).as_ref(), value)
}
+1 -1
View File
@@ -1038,7 +1038,7 @@ impl<T> Iterator for ChildTriePrefixIterator<T> {
Some(self.previous_key.clone())
} else {
sp_io::default_child_storage::next_key(
&self.child_info.storage_key(),
self.child_info.storage_key(),
&self.previous_key,
)
.filter(|n| n.starts_with(&self.prefix))
@@ -217,8 +217,7 @@ where
/// Take the value under a key.
pub fn take<KeyArg: EncodeLike<Key> + Clone>(key: KeyArg) -> QueryKind::Query {
let removed_value =
<Self as MapWrapper>::Map::mutate_exists(key, |value| core::mem::replace(value, None));
let removed_value = <Self as MapWrapper>::Map::mutate_exists(key, |value| value.take());
if removed_value.is_some() {
CounterFor::<Prefix>::mutate(|value| value.saturating_dec());
}
@@ -429,7 +428,7 @@ where
if cfg!(feature = "no-metadata-docs") {
vec![]
} else {
vec![&"Counter for the related counted storage map"]
vec!["Counter for the related counted storage map"]
},
entries,
);
@@ -481,7 +481,7 @@ where
modifier: QueryKind::METADATA,
ty: StorageEntryType::Map {
key: scale_info::meta_type::<Key::Key>(),
hashers: Key::HASHER_METADATA.iter().cloned().collect(),
hashers: Key::HASHER_METADATA.to_vec(),
value: scale_info::meta_type::<Value>(),
},
default: OnEmpty::get().encode(),
@@ -38,7 +38,7 @@ pub fn get<T: Decode + Sized>(key: &[u8]) -> Option<T> {
/// Return the value of the item in storage under `key`, or the type's default if there is no
/// explicit entry.
pub fn get_or_default<T: Decode + Sized + Default>(key: &[u8]) -> T {
get(key).unwrap_or_else(Default::default)
get(key).unwrap_or_default()
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
@@ -70,7 +70,7 @@ pub fn take<T: Decode + Sized>(key: &[u8]) -> Option<T> {
/// Remove `key` from storage, returning its value, or, if there was no explicit entry in storage,
/// the default for its type.
pub fn take_or_default<T: Decode + Sized + Default>(key: &[u8]) -> T {
take(key).unwrap_or_else(Default::default)
take(key).unwrap_or_default()
}
/// Return the value of the item in storage under `key`, or `default_value` if there is no
@@ -157,7 +157,7 @@ impl<OuterOrigin, L: EnsureOrigin<OuterOrigin>, R: EnsureOrigin<OuterOrigin>>
type Success = Either<L::Success, R::Success>;
fn try_origin(o: OuterOrigin) -> Result<Self::Success, OuterOrigin> {
L::try_origin(o)
.map_or_else(|o| R::try_origin(o).map(|o| Either::Right(o)), |o| Ok(Either::Left(o)))
.map_or_else(|o| R::try_origin(o).map(Either::Right), |o| Ok(Either::Left(o)))
}
#[cfg(feature = "runtime-benchmarks")]
@@ -299,7 +299,7 @@ pub trait ChangeMembers<AccountId: Clone + Ord> {
/// This resets any previous value of prime.
fn set_members_sorted(new_members: &[AccountId], old_members: &[AccountId]) {
let (incoming, outgoing) = Self::compute_members_diff_sorted(new_members, old_members);
Self::change_members_sorted(&incoming[..], &outgoing[..], &new_members);
Self::change_members_sorted(&incoming[..], &outgoing[..], new_members);
}
/// Compute diff between new and old members; they **must already be sorted**.
@@ -161,7 +161,7 @@ impl sp_std::cmp::Ord for CrateVersion {
impl sp_std::cmp::PartialOrd for CrateVersion {
fn partial_cmp(&self, other: &Self) -> Option<sp_std::cmp::Ordering> {
Some(<Self as Ord>::cmp(&self, other))
Some(<Self as Ord>::cmp(self, other))
}
}
+2 -2
View File
@@ -25,9 +25,9 @@ use sp_runtime::{traits::Block as BlockT, DispatchError};
use sp_std::{cmp::Ordering, prelude::*};
#[doc(hidden)]
pub const DEFENSIVE_OP_PUBLIC_ERROR: &'static str = "a defensive failure has been triggered; please report the block number at https://github.com/paritytech/substrate/issues";
pub const DEFENSIVE_OP_PUBLIC_ERROR: &str = "a defensive failure has been triggered; please report the block number at https://github.com/paritytech/substrate/issues";
#[doc(hidden)]
pub const DEFENSIVE_OP_INTERNAL_ERROR: &'static str = "Defensive failure has been triggered!";
pub const DEFENSIVE_OP_INTERNAL_ERROR: &str = "Defensive failure has been triggered!";
/// Generic function to mark an execution path as ONLY defensive.
///
@@ -101,7 +101,7 @@ impl<
}
fn remove(k: &K) -> Result<(), DispatchError> {
if S::contains_key(&k) {
L::killed(&k)?;
L::killed(k)?;
S::remove(k);
}
Ok(())
@@ -83,7 +83,7 @@ pub trait Currency<AccountId> {
/// This is just the same as burning and issuing the same amount and has no effect on the
/// total issuance.
fn pair(amount: Self::Balance) -> (Self::PositiveImbalance, Self::NegativeImbalance) {
(Self::burn(amount.clone()), Self::issue(amount))
(Self::burn(amount), Self::issue(amount))
}
/// The 'free' balance of a given account.
@@ -92,7 +92,7 @@ pub trait Mutate<AccountId>: Inspect<AccountId> {
let extra = Self::can_withdraw(&source, amount).into_result()?;
// As we first burn and then mint, we don't need to check if `mint` fits into the supply.
// If we can withdraw/burn it, we can also mint it again.
Self::can_deposit(&dest, amount.saturating_add(extra), false).into_result()?;
Self::can_deposit(dest, amount.saturating_add(extra), false).into_result()?;
let actual = Self::burn_from(source, amount)?;
debug_assert!(
actual == amount.saturating_add(extra),
@@ -165,7 +165,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
) -> Result<Self::Balance, DispatchError> {
let old_balance = Self::balance(who);
let (mut new_balance, mut amount) = if old_balance < amount {
Err(TokenError::NoFunds)?
return Err(TokenError::NoFunds.into())
} else {
(old_balance - amount, amount)
};
@@ -225,7 +225,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
let old_balance = Self::balance(who);
let new_balance = old_balance.checked_add(&amount).ok_or(ArithmeticError::Overflow)?;
if new_balance < Self::minimum_balance() {
Err(TokenError::BelowMinimum)?
return Err(TokenError::BelowMinimum.into())
}
if old_balance != new_balance {
Self::set_balance(who, new_balance)?;
@@ -145,7 +145,7 @@ pub trait Mutate<AccountId>: Inspect<AccountId> {
let extra = Self::can_withdraw(asset, &source, amount).into_result()?;
// As we first burn and then mint, we don't need to check if `mint` fits into the supply.
// If we can withdraw/burn it, we can also mint it again.
Self::can_deposit(asset, &dest, amount.saturating_add(extra), false).into_result()?;
Self::can_deposit(asset, dest, amount.saturating_add(extra), false).into_result()?;
let actual = Self::burn_from(asset, source, amount)?;
debug_assert!(
actual == amount.saturating_add(extra),
@@ -186,7 +186,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
) -> Result<Self::Balance, DispatchError> {
let old_balance = Self::balance(asset, who);
let (mut new_balance, mut amount) = if old_balance < amount {
Err(TokenError::NoFunds)?
return Err(TokenError::NoFunds.into())
} else {
(old_balance - amount, amount)
};
@@ -251,7 +251,7 @@ pub trait Unbalanced<AccountId>: Inspect<AccountId> {
let old_balance = Self::balance(asset, who);
let new_balance = old_balance.checked_add(&amount).ok_or(ArithmeticError::Overflow)?;
if new_balance < Self::minimum_balance(asset) {
Err(TokenError::BelowMinimum)?
return Err(TokenError::BelowMinimum.into())
}
if old_balance != new_balance {
Self::set_balance(asset, who, new_balance)?;
+5 -5
View File
@@ -355,7 +355,7 @@ impl PostDispatchInfo {
/// Extract the actual weight from a dispatch result if any or fall back to the default weight.
pub fn extract_actual_weight(result: &DispatchResultWithPostInfo, info: &DispatchInfo) -> Weight {
match result {
Ok(post_info) => &post_info,
Ok(post_info) => post_info,
Err(err) => &err.post_info,
}
.calc_actual_weight(info)
@@ -432,7 +432,7 @@ where
impl<T> WeighData<T> for Weight {
fn weigh_data(&self, _: T) -> Weight {
return *self
*self
}
}
@@ -450,7 +450,7 @@ impl<T> PaysFee<T> for Weight {
impl<T> WeighData<T> for (Weight, DispatchClass, Pays) {
fn weigh_data(&self, _: T) -> Weight {
return self.0
self.0
}
}
@@ -468,7 +468,7 @@ impl<T> PaysFee<T> for (Weight, DispatchClass, Pays) {
impl<T> WeighData<T> for (Weight, DispatchClass) {
fn weigh_data(&self, _: T) -> Weight {
return self.0
self.0
}
}
@@ -486,7 +486,7 @@ impl<T> PaysFee<T> for (Weight, DispatchClass) {
impl<T> WeighData<T> for (Weight, Pays) {
fn weigh_data(&self, _: T) -> Weight {
return self.0
self.0
}
}