Skip to content

Commit

Permalink
put TryInto and TryFrom in sp_std::prelude (paritytech#10183)
Browse files Browse the repository at this point in the history
* Switch to Rust 2021

* Update trybuild to fix errors

* half baked

* fix

* remove unused import

* remove more warnings

Co-authored-by: Bastian Köcher <info@kchr.de>
  • Loading branch information
2 people authored and grishasobol committed Mar 28, 2022
1 parent f4a6414 commit 7a65b59
Show file tree
Hide file tree
Showing 39 changed files with 22 additions and 48 deletions.
2 changes: 1 addition & 1 deletion frame/assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ use sp_runtime::{
},
ArithmeticError, TokenError,
};
use sp_std::{borrow::Borrow, convert::TryInto, prelude::*};
use sp_std::{borrow::Borrow, prelude::*};

#[cfg(feature = "std")]
use frame_support::traits::GenesisBuild;
Expand Down
2 changes: 1 addition & 1 deletion frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ use sp_runtime::{
traits::{IsMember, Member, SaturatedConversion, Saturating, Zero},
RuntimeAppPublic,
};
use sp_std::{convert::TryFrom, vec::Vec};
use sp_std::prelude::*;

pub mod migrations;
mod mock;
Expand Down
2 changes: 0 additions & 2 deletions frame/authority-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ use frame_support::{
use sp_authority_discovery::AuthorityId;
use sp_std::prelude::*;

use core::convert::TryFrom;

pub use pallet::*;

#[frame_support::pallet]
Expand Down
2 changes: 1 addition & 1 deletion frame/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use frame_support::{
weights::{Pays, Weight},
BoundedVec, WeakBoundedVec,
};
use sp_application_crypto::{Public, TryFrom};
use sp_application_crypto::Public;
use sp_runtime::{
generic::DigestItem,
traits::{IsMember, One, SaturatedConversion, Saturating, Zero},
Expand Down
2 changes: 1 addition & 1 deletion frame/bags-list/remote-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! Utilities for remote-testing pallet-bags-list.

use sp_std::convert::TryInto;
use sp_std::prelude::*;

/// A common log target to use.
pub const LOG_TARGET: &'static str = "runtime::bags-list::remote-tests";
Expand Down
2 changes: 1 addition & 1 deletion frame/bags-list/remote-tests/src/sanity_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::{
};
use remote_externalities::{Builder, Mode, OnlineConfig};
use sp_runtime::traits::Block as BlockT;
use sp_std::convert::TryInto;
use sp_std::prelude::*;

/// Execute the sanity check of the bags-list.
pub async fn execute<Runtime: crate::RuntimeT, Block: BlockT>(
Expand Down
1 change: 0 additions & 1 deletion frame/benchmarking/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! Tools for analyzing the benchmark results.

use crate::BenchmarkResult;
use core::convert::TryFrom;
use linregress::{FormulaRegressionBuilder, RegressionDataBuilder};
use std::collections::BTreeMap;

Expand Down
1 change: 0 additions & 1 deletion frame/contracts/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Header as HeaderT},
};
use std::convert::{TryFrom, TryInto};

pub use pallet_contracts_rpc_runtime_api::ContractsApi as ContractsRuntimeApi;

Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/benchmarking/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use pwasm_utils::parity_wasm::{
use sp_core::crypto::UncheckedFrom;
use sp_runtime::traits::Hash;
use sp_sandbox::{EnvironmentDefinitionBuilder, Memory};
use sp_std::{borrow::ToOwned, convert::TryFrom, prelude::*};
use sp_std::{borrow::ToOwned, prelude::*};

/// Pass to `create_code` in order to create a compiled `WasmModule`.
///
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use sp_runtime::{
traits::{Bounded, Hash},
Perbill,
};
use sp_std::{convert::TryInto, default::Default, vec, vec::Vec};
use sp_std::prelude::*;

/// How many batches we do per API benchmark.
const API_BENCHMARK_BATCHES: u32 = 20;
Expand Down
1 change: 0 additions & 1 deletion frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,7 +1967,6 @@ mod tests {
#[test]
#[cfg(feature = "unstable-interface")]
fn call_runtime_works() {
use std::convert::TryInto;
let call = Call::System(frame_system::Call::remark { remark: b"Hello World".to_vec() });
let mut ext = MockExt::default();
let result = execute(CODE_CALL_RUNTIME, call.encode(), &mut ext).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion frame/democracy/src/conviction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_runtime::{
traits::{Bounded, CheckedDiv, CheckedMul, Zero},
RuntimeDebug,
};
use sp_std::{convert::TryFrom, result::Result};
use sp_std::{prelude::*, result::Result};

/// A value denoting the strength of conviction of a vote.
#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, RuntimeDebug, TypeInfo)]
Expand Down
1 change: 0 additions & 1 deletion frame/democracy/src/tests/lock_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! The tests for functionality concerning locking and lock-voting.

use super::*;
use std::convert::TryFrom;

fn aye(x: u8, balance: u64) -> AccountVote<u64> {
AccountVote::Standard {
Expand Down
2 changes: 1 addition & 1 deletion frame/democracy/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use sp_runtime::{
traits::{Saturating, Zero},
RuntimeDebug,
};
use sp_std::{convert::TryFrom, prelude::*, result::Result};
use sp_std::prelude::*;

/// A number of lock periods, plus a vote, one way or the other.
#[derive(Copy, Clone, Eq, PartialEq, Default, RuntimeDebug)]
Expand Down
4 changes: 0 additions & 4 deletions frame/election-provider-multi-phase/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ use rand::{prelude::SliceRandom, rngs::SmallRng, SeedableRng};
use sp_arithmetic::{per_things::Percent, traits::One};
use sp_npos_elections::IndexAssignment;
use sp_runtime::InnerOf;
use sp_std::{
boxed::Box,
convert::{TryFrom, TryInto},
};

const SEED: u32 = 999;

Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Some helper functions/macros for this crate.

use super::{Config, SolutionTargetIndexOf, SolutionVoterIndexOf, VoteWeight};
use sp_std::{collections::btree_map::BTreeMap, convert::TryInto, prelude::*};
use sp_std::{collections::btree_map::BTreeMap, prelude::*};

#[macro_export]
macro_rules! log {
Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ use sp_runtime::{
},
DispatchError, PerThing, Perbill, RuntimeDebug, SaturatedConversion,
};
use sp_std::{convert::TryInto, prelude::*};
use sp_std::prelude::*;

#[cfg(feature = "runtime-benchmarks")]
mod benchmarking;
Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use sp_runtime::{
traits::{BlakeTwo256, IdentityLookup},
PerU16,
};
use std::{convert::TryFrom, sync::Arc};
use std::sync::Arc;

pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
pub type UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic<AccountId, Call, (), ()>;
Expand Down
2 changes: 1 addition & 1 deletion frame/election-provider-multi-phase/src/unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use sp_runtime::{
offchain::storage::{MutateStorageError, StorageValueRef},
DispatchError, SaturatedConversion,
};
use sp_std::{boxed::Box, cmp::Ordering, convert::TryFrom, vec::Vec};
use sp_std::{cmp::Ordering, prelude::*};

/// Storage key used to store the last block number at which offchain worker ran.
pub(crate) const OFFCHAIN_LAST_BLOCK: &[u8] = b"parity/multi-phase-unsigned-election";
Expand Down
2 changes: 1 addition & 1 deletion frame/identity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub mod weights;

use frame_support::traits::{BalanceStatus, Currency, OnUnbalanced, ReservableCurrency};
use sp_runtime::traits::{AppendZerosInput, Saturating, StaticLookup, Zero};
use sp_std::{convert::TryInto, prelude::*};
use sp_std::prelude::*;
pub use weights::WeightInfo;

pub use pallet::*;
Expand Down
1 change: 0 additions & 1 deletion frame/im-online/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ mod tests;
pub mod weights;

use codec::{Decode, Encode, MaxEncodedLen};
use core::convert::TryFrom;
use frame_support::{
traits::{
EstimateNextSessionRotation, Get, OneSessionHandler, ValidatorSet,
Expand Down
1 change: 0 additions & 1 deletion frame/multisig/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#![cfg(feature = "runtime-benchmarks")]

use super::*;
use core::convert::TryInto;
use frame_benchmarking::{account, benchmarks};
use frame_system::RawOrigin;
use sp_runtime::traits::Bounded;
Expand Down
2 changes: 1 addition & 1 deletion frame/randomness-collective-flip/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ use safe_mix::TripletMix;
use codec::Encode;
use frame_support::traits::Randomness;
use sp_runtime::traits::{Hash, Saturating};
use sp_std::{convert::TryInto, prelude::*};
use sp_std::prelude::*;

const RANDOM_MATERIAL_LEN: u32 = 81;

Expand Down
1 change: 0 additions & 1 deletion frame/session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ use sp_runtime::{
};
use sp_staking::SessionIndex;
use sp_std::{
convert::TryFrom,
marker::PhantomData,
ops::{Rem, Sub},
prelude::*,
Expand Down
2 changes: 0 additions & 2 deletions frame/staking/reward-curve/src/log.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::convert::TryInto;

/// Simple u32 power of 2 function - simply uses a bit shift
macro_rules! pow2 {
($n:expr) => {
Expand Down
1 change: 0 additions & 1 deletion frame/staking/reward-fn/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

//! Useful function for inflation for nominated proof of stake.

use core::convert::TryFrom;
use sp_arithmetic::{
biguint::BigUint,
traits::{SaturatedConversion, Zero},
Expand Down
1 change: 0 additions & 1 deletion frame/staking/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ benchmarks! {
}

unbond {
use sp_std::convert::TryFrom;
// clean up any existing state.
clear_validators_and_nominators::<T>();

Expand Down
1 change: 0 additions & 1 deletion frame/support/procedural/src/pallet/parse/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// limitations under the License.

use super::helper;
use core::convert::TryFrom;
use frame_support_procedural_tools::get_doc_literals;
use quote::ToTokens;
use syn::spanned::Spanned;
Expand Down
1 change: 0 additions & 1 deletion frame/support/src/storage/bounded_btree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ pub mod test {
use super::*;
use crate::Twox128;
use sp_io::TestExternalities;
use sp_std::convert::TryInto;

crate::parameter_types! {
pub const Seven: u32 = 7;
Expand Down
3 changes: 1 addition & 2 deletions frame/support/src/storage/bounded_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use core::{
ops::{Deref, Index, IndexMut},
slice::SliceIndex,
};
use sp_std::{convert::TryFrom, marker::PhantomData, prelude::*};
use sp_std::{marker::PhantomData, prelude::*};

/// A bounded vector.
///
Expand Down Expand Up @@ -349,7 +349,6 @@ pub mod test {
use super::*;
use crate::Twox128;
use sp_io::TestExternalities;
use sp_std::convert::TryInto;

crate::parameter_types! {
pub const Seven: u32 = 7;
Expand Down
1 change: 0 additions & 1 deletion frame/support/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,6 @@ mod test {
use super::*;
use crate::{assert_ok, hash::Identity, Twox128};
use bounded_vec::BoundedVec;
use core::convert::{TryFrom, TryInto};
use generator::StorageValue as _;
use sp_core::hashing::twox_128;
use sp_io::TestExternalities;
Expand Down
6 changes: 1 addition & 5 deletions frame/system/src/offchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ use sp_runtime::{
app_crypto::RuntimeAppPublic,
traits::{Extrinsic as ExtrinsicT, IdentifyAccount, One},
};
use sp_std::{
collections::btree_set::BTreeSet,
convert::{TryFrom, TryInto},
prelude::{Box, Vec},
};
use sp_std::{collections::btree_set::BTreeSet, prelude::*};

/// Marker struct used to flag using all supported keys to sign a payload.
pub struct ForAll {}
Expand Down
2 changes: 1 addition & 1 deletion frame/transaction-payment/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, MaybeDisplay},
};
use std::{convert::TryInto, sync::Arc};
use std::sync::Arc;

#[rpc]
pub trait TransactionPaymentApi<BlockHash, ResponseType> {
Expand Down
1 change: 0 additions & 1 deletion frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ pub mod pallet {
// given weight == u64, we build multipliers from `diff` of two weight values, which can
// at most be maximum block weight. Make sure that this can fit in a multiplier without
// loss.
use sp_std::convert::TryInto;
assert!(
<Multiplier as sp_runtime::traits::Bounded>::max_value() >=
Multiplier::checked_from_integer(
Expand Down
2 changes: 1 addition & 1 deletion frame/uniques/src/impl_nonfungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use frame_support::{
BoundedSlice,
};
use sp_runtime::{DispatchError, DispatchResult};
use sp_std::convert::TryFrom;
use sp_std::prelude::*;

impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Pallet<T, I> {
type InstanceId = T::InstanceId;
Expand Down
2 changes: 1 addition & 1 deletion frame/uniques/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use super::*;
use crate::mock::*;
use frame_support::{assert_noop, assert_ok, traits::Currency};
use pallet_balances::Error as BalancesError;
use sp_std::convert::TryInto;
use sp_std::prelude::*;

fn assets() -> Vec<(u64, u32, u32)> {
let mut r: Vec<_> = Account::<Test>::iter().map(|x| x.0).collect();
Expand Down
2 changes: 2 additions & 0 deletions primitives/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pub mod prelude {
boxed::Box,
clone::Clone,
cmp::{Eq, PartialEq, Reverse},
convert::{TryFrom, TryInto},
iter::IntoIterator,
vec::Vec,
};

Expand Down
1 change: 0 additions & 1 deletion utils/frame/benchmarking-cli/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

// Outputs benchmark results to Rust files that can be ingested by the runtime.

use core::convert::TryInto;
use std::{
collections::{HashMap, HashSet},
fs,
Expand Down
1 change: 0 additions & 1 deletion utils/frame/frame-utilities-cli/src/pallet_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use sc_cli::{
};
use sp_core::crypto::{unwrap_or_default_ss58_version, Ss58AddressFormat, Ss58Codec};
use sp_runtime::traits::AccountIdConversion;
use std::convert::{TryFrom, TryInto};
use structopt::StructOpt;

/// The `palletid` command
Expand Down

0 comments on commit 7a65b59

Please sign in to comment.