put TryInto and TryFrom in sp_std::prelude (#10183)

* 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>
This commit is contained in:
Kian Paimani
2021-11-07 23:24:53 +00:00
committed by GitHub
parent ca5b07243f
commit 937b6f246e
39 changed files with 22 additions and 48 deletions
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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;
@@ -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]
+1 -1
View File
@@ -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},
@@ -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";
@@ -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>(
@@ -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;
-1
View File
@@ -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;
@@ -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`.
///
@@ -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;
@@ -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();
+1 -1
View File
@@ -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)]
@@ -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 {
+1 -1
View File
@@ -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)]
@@ -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;
@@ -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 {
@@ -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;
@@ -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, (), ()>;
@@ -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";
+1 -1
View File
@@ -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::*;
-1
View File
@@ -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,
@@ -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;
@@ -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;
-1
View File
@@ -131,7 +131,6 @@ use sp_runtime::{
};
use sp_staking::SessionIndex;
use sp_std::{
convert::TryFrom,
marker::PhantomData,
ops::{Rem, Sub},
prelude::*,
@@ -1,5 +1,3 @@
use std::convert::TryInto;
/// Simple u32 power of 2 function - simply uses a bit shift
macro_rules! pow2 {
($n:expr) => {
@@ -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},
@@ -256,7 +256,6 @@ benchmarks! {
}
unbond {
use sp_std::convert::TryFrom;
// clean up any existing state.
clear_validators_and_nominators::<T>();
@@ -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;
@@ -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;
@@ -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.
///
@@ -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;
@@ -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;
+1 -5
View File
@@ -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 {}
@@ -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> {
@@ -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(
@@ -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;
+1 -1
View File
@@ -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();
+2
View File
@@ -98,6 +98,8 @@ pub mod prelude {
boxed::Box,
clone::Clone,
cmp::{Eq, PartialEq, Reverse},
convert::{TryFrom, TryInto},
iter::IntoIterator,
vec::Vec,
};
@@ -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,
@@ -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