Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ edition = "2024"

[workspace.lints.clippy]
arithmetic-side-effects = "deny"
expect-used = "deny"
indexing-slicing = "deny"
manual_inspect = "allow"
result_large_err = "allow"
Expand Down
1 change: 1 addition & 0 deletions node/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
// Create a transaction using the given `call`.
//
// Note: Should only be used for benchmarking.
#[allow(clippy::expect_used)]
pub fn create_benchmark_extrinsic(
client: &FullClient,
sender: sp_core::sr25519::Pair,
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Allowed since it's actually better to panic during chain setup when there is an error
#![allow(clippy::unwrap_used)]
#![allow(clippy::expect_used, clippy::unwrap_used)]

pub mod devnet;
pub mod finney;
Expand Down
3 changes: 3 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ pub fn run() -> sc_cli::Result<()> {
}
}

#[allow(clippy::expect_used)]
fn start_babe_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
let cli = Cli::from_arg_matches(arg_matches).expect("Bad arg_matches");
let runner = cli.create_runner(&cli.run)?;
Expand Down Expand Up @@ -281,6 +282,7 @@ fn start_babe_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
}
}

#[allow(clippy::expect_used)]
fn start_aura_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
let cli = Cli::from_arg_matches(arg_matches).expect("Bad arg_matches");
let runner = cli.create_runner(&cli.run)?;
Expand Down Expand Up @@ -313,6 +315,7 @@ fn start_aura_service(arg_matches: &ArgMatches) -> Result<(), sc_cli::Error> {
}
}

#[allow(clippy::expect_used)]
fn customise_config(arg_matches: &ArgMatches, config: Configuration) -> Configuration {
let cli = Cli::from_arg_matches(arg_matches).expect("Bad arg_matches");

Expand Down
1 change: 1 addition & 0 deletions node/src/consensus/babe_consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl ConsensusMechanism for BabeConsensus {
sp_timestamp::InherentDataProvider,
);

#[allow(clippy::expect_used)]
fn start_authoring<C, SC, I, PF, SO, L, CIDP, BS, Error>(
self,
task_manager: &mut TaskManager,
Expand Down
1 change: 1 addition & 0 deletions node/src/consensus/hybrid_import_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl HybridBlockImport {
FrontierBlockImport::new(grandpa_block_import.clone(), client.clone()),
);

#[allow(clippy::expect_used)]
let (babe_import, babe_link) = sc_consensus_babe::block_import(
babe_config,
grandpa_block_import.clone(),
Expand Down
2 changes: 2 additions & 0 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub type BIQ<'a> = Box<
+ 'a,
>;

#[allow(clippy::expect_used)]
pub fn new_partial(
config: &Configuration,
eth_config: &EthConfiguration,
Expand Down Expand Up @@ -250,6 +251,7 @@ pub fn build_manual_seal_import_queue(
}

/// Builds a new service for a full client.
#[allow(clippy::expect_used)]
pub async fn new_full<NB, CM>(
mut config: Configuration,
eth_config: EthConfiguration,
Expand Down
3 changes: 3 additions & 0 deletions pallets/admin-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod tests;

#[deny(missing_docs)]
#[frame_support::pallet]
#[allow(clippy::expect_used)]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
Expand Down Expand Up @@ -162,6 +163,8 @@ pub mod pallet {
/// Dispatchable functions allows users to interact with the pallet and invoke state changes.
#[pallet::call]
impl<T: Config> Pallet<T> {
#![deny(clippy::expect_used)]

/// The extrinsic sets the new authorities for Aura consensus.
/// It is only callable by the root account.
/// The extrinsic will call the Aura pallet to change the authorities.
Expand Down
6 changes: 5 additions & 1 deletion pallets/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
// limitations under the License.

//! Staking pallet benchmarking.
#![allow(clippy::arithmetic_side_effects, clippy::indexing_slicing)]
#![allow(
clippy::arithmetic_side_effects,
clippy::expect_used,
clippy::indexing_slicing
)]

use super::*;
use crate::Pallet as Collective;
Expand Down
4 changes: 4 additions & 0 deletions pallets/collective/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub struct Votes<AccountId, BlockNumber> {

#[deny(missing_docs)]
#[frame_support::pallet]
#[allow(clippy::expect_used)]
pub mod pallet {
use super::*;
use frame_system::pallet_prelude::*;
Expand Down Expand Up @@ -397,6 +398,8 @@ pub mod pallet {
// Note that councillor operations are assigned to the operational class.
#[pallet::call]
impl<T: Config<I>, I: 'static> Pallet<T, I> {
#![deny(clippy::expect_used)]

/// Set the collective's membership.
///
/// - `new_members`: The new member list. Be nice to the chain and provide it sorted.
Expand Down Expand Up @@ -1128,6 +1131,7 @@ impl<
}

#[cfg(feature = "runtime-benchmarks")]
#[allow(clippy::expect_used)]
fn try_successful_origin() -> Result<O, ()> {
let zero_account_id =
AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes())
Expand Down
7 changes: 6 additions & 1 deletion pallets/collective/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![allow(non_camel_case_types, clippy::indexing_slicing, clippy::unwrap_used)]
#![allow(
non_camel_case_types,
clippy::expect_used,
clippy::indexing_slicing,
clippy::unwrap_used
)]

use super::{Event as CollectiveEvent, *};
use crate as pallet_collective;
Expand Down
2 changes: 1 addition & 1 deletion pallets/commitments/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Benchmarking setup
#![cfg(feature = "runtime-benchmarks")]
#![allow(clippy::arithmetic_side_effects)]
#![allow(clippy::arithmetic_side_effects, clippy::expect_used)]
use super::*;

#[allow(unused)]
Expand Down
3 changes: 3 additions & 0 deletions pallets/commitments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
#[deny(missing_docs)]
#[frame_support::pallet]
#[allow(clippy::expect_used)]
pub mod pallet {
use super::*;
use frame_support::{pallet_prelude::*, traits::ReservableCurrency};
Expand Down Expand Up @@ -204,6 +205,8 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#![deny(clippy::expect_used)]

/// Set the commitment for a given netuid
#[pallet::call_index(0)]
#[pallet::weight((
Expand Down
1 change: 1 addition & 0 deletions pallets/commitments/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::expect_used)]
use crate as pallet_commitments;
use frame_support::{
derive_impl,
Expand Down
3 changes: 2 additions & 1 deletion pallets/commitments/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::expect_used, clippy::indexing_slicing)]

use codec::Encode;
use sp_std::prelude::*;
use subtensor_runtime_common::NetUid;
Expand All @@ -19,7 +21,6 @@ use frame_support::{
};
use frame_system::{Pallet as System, RawOrigin};

#[allow(clippy::indexing_slicing)]
#[test]
fn manual_data_type_info() {
let mut registry = scale_info::Registry::new();
Expand Down
2 changes: 1 addition & 1 deletion pallets/commitments/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Decode for Data {
n @ 1..=129 => {
let mut r: BoundedVec<_, _> = vec![0u8; (n as usize).saturating_sub(1)]
.try_into()
.expect("bound checked in match arm condition; qed");
.map_err(|_| codec::Error::from("bound checked in match arm condition; qed"))?;
input.read(&mut r[..])?;
Data::Raw(r)
}
Expand Down
3 changes: 3 additions & 0 deletions pallets/crowdloan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ pub type CrowdloanInfoOf<T> = CrowdloanInfo<
>;

#[frame_support::pallet]
#[allow(clippy::expect_used)]
pub mod pallet {
use super::*;

Expand Down Expand Up @@ -285,6 +286,8 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#![deny(clippy::expect_used)]

/// Create a crowdloan that will raise funds up to a maximum cap and if successful,
/// will transfer funds to the target address if provided and dispatch the call
/// (using creator origin).
Expand Down
6 changes: 5 additions & 1 deletion pallets/crowdloan/src/mock.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#![cfg(test)]
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
#![allow(
clippy::arithmetic_side_effects,
clippy::expect_used,
clippy::unwrap_used
)]
use frame_support::{
PalletId, derive_impl, parameter_types,
traits::{OnFinalize, OnInitialize, fungible, fungible::*, tokens::Preservation},
Expand Down
8 changes: 5 additions & 3 deletions pallets/proxy/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// Benchmarks for Proxy Pallet

#![cfg(feature = "runtime-benchmarks")]
#![allow(clippy::arithmetic_side_effects)]
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]

use super::*;
use crate::Pallet as Proxy;
Expand Down Expand Up @@ -321,7 +321,8 @@ mod benchmarks {
0,
);

let pure_account = Pallet::<T>::pure_account(&caller, &T::ProxyType::default(), 0, None);
let pure_account =
Pallet::<T>::pure_account(&caller, &T::ProxyType::default(), 0, None).unwrap();
assert_last_event::<T>(
Event::PureCreated {
pure: pure_account,
Expand All @@ -348,7 +349,8 @@ mod benchmarks {
)?;
let height = T::BlockNumberProvider::current_block_number();
let ext_index = frame_system::Pallet::<T>::extrinsic_index().unwrap_or(0);
let pure_account = Pallet::<T>::pure_account(&caller, &T::ProxyType::default(), 0, None);
let pure_account =
Pallet::<T>::pure_account(&caller, &T::ProxyType::default(), 0, None).unwrap();

add_proxies::<T>(p, Some(pure_account.clone()))?;
ensure!(
Expand Down
32 changes: 20 additions & 12 deletions pallets/proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ pub enum DepositKind {
}

#[frame::pallet]
#[allow(clippy::expect_used)]
pub mod pallet {
use super::*;

Expand Down Expand Up @@ -215,6 +216,8 @@ pub mod pallet {

#[pallet::call]
impl<T: Config> Pallet<T> {
#![deny(clippy::expect_used)]

/// Dispatch the given `call` from an account that the sender is authorised for through
/// `add_proxy`.
///
Expand Down Expand Up @@ -333,7 +336,7 @@ pub mod pallet {
) -> DispatchResult {
let who = ensure_signed(origin)?;

let pure = Self::pure_account(&who, &proxy_type, index, None);
let pure = Self::pure_account(&who, &proxy_type, index, None)?;
ensure!(!Proxies::<T>::contains_key(&pure), Error::<T>::Duplicate);

let proxy_def = ProxyDefinition {
Expand Down Expand Up @@ -389,7 +392,7 @@ pub mod pallet {
let spawner = T::Lookup::lookup(spawner)?;

let when = (height, ext_index);
let proxy = Self::pure_account(&spawner, &proxy_type, index, Some(when));
let proxy = Self::pure_account(&spawner, &proxy_type, index, Some(when))?;
ensure!(proxy == who, Error::<T>::NoPermission);

let (_, deposit) = Proxies::<T>::take(&who);
Expand Down Expand Up @@ -445,24 +448,24 @@ pub mod pallet {
pending
.try_push(announcement)
.map_err(|_| Error::<T>::TooMany)?;
Self::rejig_deposit(
let new_deposit = Self::rejig_deposit(
&who,
*deposit,
T::AnnouncementDepositBase::get(),
T::AnnouncementDepositFactor::get(),
pending.len(),
)
.map(|d| {
d.expect("Just pushed; pending.len() > 0; rejig_deposit returns Some; qed")
})
.map(|d| *deposit = d)
)?
.ok_or(Error::<T>::AnnouncementDepositInvariantViolated)?;

*deposit = new_deposit;
Ok::<(), DispatchError>(())
})?;

Self::deposit_event(Event::Announced {
real,
proxy: who,
call_hash,
});

Ok(())
}

Expand Down Expand Up @@ -743,6 +746,10 @@ pub mod pallet {
Unannounced,
/// Cannot add self as proxy.
NoSelfProxy,
/// Invariant violated: deposit recomputation returned None after updating announcements.
AnnouncementDepositInvariantViolated,
/// Failed to derive a valid account id from the provided entropy.
InvalidDerivedAccountId,
}

/// The set of account proxies. Maps the account which has delegated to the accounts
Expand Down Expand Up @@ -829,7 +836,7 @@ impl<T: Config> Pallet<T> {
proxy_type: &T::ProxyType,
index: u16,
maybe_when: Option<(BlockNumberFor<T>, u32)>,
) -> T::AccountId {
) -> Result<T::AccountId, DispatchError> {
let (height, ext_index) = maybe_when.unwrap_or_else(|| {
(
T::BlockNumberProvider::current_block_number(),
Expand All @@ -845,8 +852,9 @@ impl<T: Config> Pallet<T> {
index,
)
.using_encoded(blake2_256);
Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.expect("infinite length input; no invalid inputs for type; qed")

T::AccountId::decode(&mut TrailingZeroInput::new(entropy.as_ref()))
.map_err(|_| Error::<T>::InvalidDerivedAccountId.into())
}

/// Register a proxy account for the delegator that is able to make calls on its behalf.
Expand Down
6 changes: 3 additions & 3 deletions pallets/proxy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ fn filtering_works() {
.into(),
);

let derivative_id = Utility::derivative_account_id(1, 0);
let derivative_id = Utility::derivative_account_id(1, 0).unwrap();
Balances::make_free_balance_be(&derivative_id, 1000);
let inner = Box::new(call_transfer(6, 1));

Expand Down Expand Up @@ -876,7 +876,7 @@ fn pure_works() {
0,
0
));
let anon = Proxy::pure_account(&1, &ProxyType::Any, 0, None);
let anon = Proxy::pure_account(&1, &ProxyType::Any, 0, None).unwrap();
System::assert_last_event(
ProxyEvent::PureCreated {
pure: anon,
Expand All @@ -900,7 +900,7 @@ fn pure_works() {
0,
1
));
let anon2 = Proxy::pure_account(&2, &ProxyType::Any, 0, None);
let anon2 = Proxy::pure_account(&2, &ProxyType::Any, 0, None).unwrap();
assert_ok!(Proxy::create_pure(
RuntimeOrigin::signed(2),
ProxyType::Any,
Expand Down
6 changes: 5 additions & 1 deletion pallets/registry/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
//! Benchmarking setup
#![cfg(feature = "runtime-benchmarks")]
#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)]
#![allow(
clippy::arithmetic_side_effects,
clippy::expect_used,
clippy::unwrap_used
)]
use super::*;

#[allow(unused)]
Expand Down
Loading
Loading