Skip to content

Commit

Permalink
Relaxed clippy fixes/nits (paritytech#2661)
Browse files Browse the repository at this point in the history
This PR contains just a few clippy fixes and nits, which are, however,
relaxed by workspace clippy settings here:
https://github.com/paritytech/polkadot-sdk/blob/master/Cargo.toml#L483-L506

---------

Co-authored-by: Dmitry Sinyavin <dmitry.sinyavin@parity.io>
Co-authored-by: ordian <write@reusable.software>
Co-authored-by: command-bot <>
Co-authored-by: Bastian Köcher <git@kchr.de>
  • Loading branch information
4 people authored Dec 18, 2023
1 parent 373d032 commit 6d94b5b
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion substrate/client/chain-spec/src/genesis_config_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ where
mod tests {
use super::*;
use serde_json::{from_str, json};
pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration, Slot};
pub use sp_consensus_babe::{AllowedSlots, BabeEpochConfiguration};

#[test]
fn get_default_config_works() {
Expand Down
8 changes: 2 additions & 6 deletions substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@
pub use sp_core::H256;
use sp_runtime::traits::Hash;
pub use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
BuildStorage,
};
pub use sp_runtime::{traits::BlakeTwo256, BuildStorage};
use sp_std::convert::{TryFrom, TryInto};

pub use frame_support::{
assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types,
traits::{EitherOfDiverse, SortedMembers},
BoundedVec,
traits::EitherOfDiverse, BoundedVec,
};
use frame_system::{EnsureRoot, EnsureSignedBy};
use pallet_identity::{
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn add_sufficients<T: Config<I>, I: 'static>(minter: T::AccountId, n: u32) {

fn add_approvals<T: Config<I>, I: 'static>(minter: T::AccountId, n: u32) {
let asset_id = default_asset_id::<T, I>();
T::Currency::deposit_creating(
let _ = T::Currency::deposit_creating(
&minter,
T::ApprovalDeposit::get() * n.into() + T::Currency::minimum_balance(),
);
Expand Down
5 changes: 1 addition & 4 deletions substrate/frame/beefy/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ use sp_state_machine::BasicExternalities;

use crate as pallet_beefy;

pub use sp_consensus_beefy::{
ecdsa_crypto::{AuthorityId as BeefyId, AuthoritySignature as BeefySignature},
ConsensusLog, EquivocationProof, BEEFY_ENGINE_ID,
};
pub use sp_consensus_beefy::{ecdsa_crypto::AuthorityId as BeefyId, ConsensusLog, BEEFY_ENGINE_ID};

impl_opaque_keys! {
pub struct MockSessionKeys {
Expand Down
2 changes: 0 additions & 2 deletions substrate/frame/broker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ pub use weights::WeightInfo;
pub use adapt_price::*;
pub use core_mask::*;
pub use coretime_interface::*;
pub use nonfungible_impl::*;
pub use types::*;
pub use utility_impls::*;

#[frame_support::pallet]
pub mod pallet {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/contracts/src/migration/v10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ where
"Failed to transfer the base deposit, reason: {:?}",
err
);
OldCurrency::deposit_creating(&deposit_account, min_balance);
let _ = OldCurrency::deposit_creating(&deposit_account, min_balance);
min_balance
});

Expand Down
8 changes: 5 additions & 3 deletions substrate/frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ mod runtime;
pub use crate::wasm::runtime::api_doc;

pub use crate::wasm::runtime::{
AllowDeprecatedInterface, AllowUnstableInterface, Environment, ReturnErrorCode, Runtime,
RuntimeCosts,
AllowDeprecatedInterface, AllowUnstableInterface, Environment, Runtime, RuntimeCosts,
};
pub use pallet_contracts_uapi::ReturnFlags;

#[cfg(test)]
pub use tests::MockExt;

#[cfg(test)]
pub use crate::wasm::runtime::ReturnErrorCode;

use crate::{
exec::{ExecResult, Executable, ExportedFunction, Ext},
gas::{GasMeter, Token},
Expand Down
10 changes: 5 additions & 5 deletions substrate/frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use frame_election_provider_support::{
bounds::{DataProviderBounds, ElectionBounds},
data_provider, onchain, ElectionDataProvider, NposSolution, SequentialPhragmen,
};
pub use frame_support::{assert_noop, assert_ok, derive_impl, pallet_prelude::GetDefault};
pub use frame_support::derive_impl;
use frame_support::{
parameter_types,
traits::{ConstU32, Hooks},
Expand Down Expand Up @@ -117,7 +117,7 @@ pub fn roll_to_round(n: u32) {

while MultiPhase::round() != n {
roll_to_signed();
assert_ok!(MultiPhase::elect());
frame_support::assert_ok!(MultiPhase::elect());
}
}

Expand Down Expand Up @@ -638,9 +638,9 @@ impl ExtBuilder {

#[cfg(feature = "try-runtime")]
ext.execute_with(|| {
assert_ok!(<MultiPhase as frame_support::traits::Hooks<u64>>::try_state(
System::block_number()
));
frame_support::assert_ok!(
<MultiPhase as frame_support::traits::Hooks<u64>>::try_state(System::block_number())
);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/elections-phragmen/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn endowed_account<T: Config>(name: &'static str, index: u32) -> T::AccountId {
let _ = T::Currency::make_free_balance_be(&account, amount);
// important to increase the total issuance since T::CurrencyToVote will need it to be sane for
// phragmen to work.
T::Currency::issue(amount);
let _ = T::Currency::issue(amount);

account
}
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/fast-unstake/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ pub mod pallet {
.any(|e| T::Staking::is_exposed_in_era(&stash, e));

if is_exposed {
T::Currency::slash_reserved(&stash, deposit);
let _ = T::Currency::slash_reserved(&stash, deposit);
log!(info, "slashed {:?} by {:?}", stash, deposit);
Self::deposit_event(Event::<T>::Slashed { stash, amount: deposit });
false
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/indices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ pub mod pallet {
let (account, amount, perm) = maybe_value.take().ok_or(Error::<T>::NotAssigned)?;
ensure!(!perm, Error::<T>::Permanent);
ensure!(account == who, Error::<T>::NotOwner);
T::Currency::slash_reserved(&who, amount);
let _ = T::Currency::slash_reserved(&who, amount);
*maybe_value = Some((account, Zero::zero(), true));
Ok(())
})?;
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/lottery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ pub mod pallet {
// Make sure pot exists.
let lottery_account = Self::account_id();
if T::Currency::total_balance(&lottery_account).is_zero() {
T::Currency::deposit_creating(&lottery_account, T::Currency::minimum_balance());
let _ =
T::Currency::deposit_creating(&lottery_account, T::Currency::minimum_balance());
}
Self::deposit_event(Event::<T>::LotteryStarted);
Ok(())
Expand Down
12 changes: 5 additions & 7 deletions substrate/frame/paged-list/src/paged_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,11 @@ where
#[allow(dead_code)]
pub(crate) mod mock {
pub use super::*;
pub use frame_support::{
parameter_types,
storage::{types::ValueQuery, StorageList as _},
StorageNoopGuard,
};
pub use sp_io::{hashing::twox_128, TestExternalities};
pub use sp_metadata_ir::{StorageEntryModifierIR, StorageEntryTypeIR, StorageHasherIR};
pub use frame_support::parameter_types;
#[cfg(test)]
pub use frame_support::{storage::StorageList as _, StorageNoopGuard};
#[cfg(test)]
pub use sp_io::TestExternalities;

parameter_types! {
pub const ValuesPerNewPage: u32 = 5;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ benchmarks! {
let original_bonded: BalanceOf<T>
= Ledger::<T>::get(&controller).map(|l| l.active).ok_or("ledger not created after")?;

T::Currency::deposit_into_existing(&stash, max_additional).unwrap();
let _ = T::Currency::deposit_into_existing(&stash, max_additional).unwrap();

whitelist_account!(stash);
}: _(RawOrigin::Signed(stash), max_additional)
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/support/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ mod weight_tests {
use sp_runtime::{generic, traits::BlakeTwo256};
use sp_weights::RuntimeDbWeight;

pub use self::frame_system::{Call, Config, Pallet};
pub use self::frame_system::{Call, Config};

fn from_actual_ref_time(ref_time: Option<u64>) -> PostDispatchInfo {
PostDispatchInfo {
Expand Down
4 changes: 3 additions & 1 deletion substrate/primitives/database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ pub trait Database<H: Clone + AsRef<[u8]>>: Send + Sync {
/// This may be faster than `get` since it doesn't allocate.
/// Use `with_get` helper function if you need `f` to return a value from `f`
fn with_get(&self, col: ColumnId, key: &[u8], f: &mut dyn FnMut(&[u8])) {
self.get(col, key).map(|v| f(&v));
if let Some(v) = self.get(col, key) {
f(&v)
}
}

/// Check if database supports internal ref counting for state data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct RuntimeInterfaceFunctionSet {
impl RuntimeInterfaceFunctionSet {
fn new(version: VersionAttribute, trait_item: &TraitItemFn) -> Result<Self> {
Ok(Self {
latest_version_to_call: version.is_callable().then(|| version.version),
latest_version_to_call: version.is_callable().then_some(version.version),
versions: BTreeMap::from([(
version.version,
RuntimeInterfaceFunction::new(trait_item)?,
Expand Down
9 changes: 2 additions & 7 deletions substrate/primitives/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,13 @@ impl ChildTrieParentKeyId {
///
/// V0 and V1 uses a same trie implementation, but V1 will write external value node in the trie for
/// value with size at least `TRIE_VALUE_NODE_THRESHOLD`.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq)]
#[cfg_attr(feature = "std", derive(Encode, Decode))]
pub enum StateVersion {
/// Old state version, no value nodes.
V0 = 0,
/// New state version can use value nodes.
#[default]
V1 = 1,
}

Expand All @@ -432,12 +433,6 @@ impl Display for StateVersion {
}
}

impl Default for StateVersion {
fn default() -> Self {
StateVersion::V1
}
}

impl From<StateVersion> for u8 {
fn from(version: StateVersion) -> u8 {
version as u8
Expand Down
10 changes: 8 additions & 2 deletions substrate/utils/build-script-utils/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::{env, fs, fs::File, io, io::Read, path::PathBuf};
use std::{
env, fs,
fs::File,
io,
io::Read,
path::{Path, PathBuf},
};

/// Make sure the calling `build.rs` script is rerun when `.git/HEAD` or the ref of `.git/HEAD`
/// changed.
Expand Down Expand Up @@ -55,7 +61,7 @@ pub fn rerun_if_git_head_changed() {
}

// Code taken from https://github.com/rustyhorde/vergen/blob/8d522db8c8e16e26c0fc9ea8e6b0247cbf5cca84/src/output/envvar.rs
fn get_git_paths(path: &PathBuf) -> Result<Option<Vec<PathBuf>>, io::Error> {
fn get_git_paths(path: &Path) -> Result<Option<Vec<PathBuf>>, io::Error> {
let git_dir_or_file = path.join(".git");

if let Ok(metadata) = fs::metadata(&git_dir_or_file) {
Expand Down
2 changes: 1 addition & 1 deletion substrate/utils/build-script-utils/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub fn generate_cargo_keys() {
// We deliberately set the length here to `11` to ensure that
// the emitted hash is always of the same length; otherwise
// it can (and will!) vary between different build environments.
match Command::new("git").args(&["rev-parse", "--short=11", "HEAD"]).output() {
match Command::new("git").args(["rev-parse", "--short=11", "HEAD"]).output() {
Ok(o) if o.status.success() => {
let sha = String::from_utf8_lossy(&o.stdout).trim().to_owned();
Cow::from(sha)
Expand Down

0 comments on commit 6d94b5b

Please sign in to comment.