Remove useless imports (#11136)

Because `TryInto`/`TryFrom` are in prelude by default from edition 2021

Signed-off-by: koushiro <koushiro.cqx@gmail.com>
This commit is contained in:
Qinxuan Chen
2022-04-04 03:44:29 +08:00
committed by GitHub
parent 98ed4afe45
commit 41c84b0b41
91 changed files with 81 additions and 176 deletions
@@ -42,7 +42,7 @@ pub use scale_info;
#[cfg(feature = "std")]
pub use serde;
#[doc(hidden)]
pub use sp_std::{convert::TryFrom, ops::Deref, vec::Vec};
pub use sp_std::{ops::Deref, vec::Vec};
pub mod ecdsa;
pub mod ed25519;
@@ -363,7 +363,7 @@ macro_rules! app_crypto_public_common {
}
}
impl<'a> $crate::TryFrom<&'a [u8]> for Public {
impl<'a> TryFrom<&'a [u8]> for Public {
type Error = ();
fn try_from(data: &'a [u8]) -> Result<Self, Self::Error> {
@@ -518,7 +518,7 @@ macro_rules! app_crypto_signature_common {
type Generic = $sig;
}
impl<'a> $crate::TryFrom<&'a [u8]> for Signature {
impl<'a> TryFrom<&'a [u8]> for Signature {
type Error = ();
fn try_from(data: &'a [u8]) -> Result<Self, Self::Error> {
@@ -526,7 +526,7 @@ macro_rules! app_crypto_signature_common {
}
}
impl $crate::TryFrom<$crate::Vec<u8>> for Signature {
impl TryFrom<$crate::Vec<u8>> for Signature {
type Error = ();
fn try_from(data: $crate::Vec<u8>) -> Result<Self, Self::Error> {
@@ -29,7 +29,6 @@
use honggfuzz::fuzz;
use sp_arithmetic::biguint::{BigUint, Single};
use std::convert::TryFrom;
fn main() {
loop {
@@ -25,7 +25,6 @@
use honggfuzz::fuzz;
use sp_arithmetic::Normalizable;
use std::convert::TryInto;
type Ty = u64;
@@ -19,7 +19,7 @@
use codec::{Decode, Encode};
use num_traits::{One, Zero};
use sp_std::{cell::RefCell, cmp::Ordering, convert::TryFrom, ops, prelude::*, vec};
use sp_std::{cell::RefCell, cmp::Ordering, ops, prelude::*, vec};
// A sensible value for this would be half of the dword size of the host machine. Since the
// runtime is compiled to 32bit webassembly, using 32 and 64 for single and double respectively
@@ -664,7 +664,6 @@ pub mod tests {
#[test]
fn can_try_build_numbers_from_types() {
use sp_std::convert::TryFrom;
assert_eq!(u64::try_from(with_limbs(1)).unwrap(), 1);
assert_eq!(u64::try_from(with_limbs(2)).unwrap(), u32::MAX as u64 + 2);
assert_eq!(u64::try_from(with_limbs(3)).unwrap_err(), "cannot fit a number into u64");
@@ -27,7 +27,6 @@ use crate::{
};
use codec::{CompactAs, Decode, Encode};
use sp_std::{
convert::{TryFrom, TryInto},
fmt::Debug,
ops::{self, Add, Div, Mul, Sub},
prelude::*,
@@ -24,7 +24,6 @@ use crate::biguint;
use num_traits::Zero;
use sp_std::{
cmp::{max, min},
convert::TryInto,
mem,
};
+1 -1
View File
@@ -44,7 +44,7 @@ pub use fixed_point::{FixedI128, FixedI64, FixedPointNumber, FixedPointOperand,
pub use per_things::{InnerOf, PerThing, PerU16, Perbill, Percent, Permill, Perquintill, UpperOf};
pub use rational::{Rational128, RationalInfinite};
use sp_std::{cmp::Ordering, convert::TryInto, fmt::Debug, prelude::*};
use sp_std::{cmp::Ordering, fmt::Debug, prelude::*};
use traits::{BaseArithmetic, One, SaturatedConversion, Unsigned, Zero};
/// Trait for comparing two numbers with an threshold.
@@ -25,7 +25,6 @@ use crate::traits::{
use codec::{CompactAs, Encode};
use num_traits::{Pow, SaturatingAdd, SaturatingSub};
use sp_std::{
convert::{TryFrom, TryInto},
fmt, ops,
ops::{Add, Sub},
prelude::*,
@@ -23,12 +23,8 @@ pub use num_traits::{
checked_pow, Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl,
CheckedShr, CheckedSub, One, Signed, Unsigned, Zero,
};
use sp_std::{
self,
convert::{TryFrom, TryInto},
ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, Shr, Sub, SubAssign,
},
use sp_std::ops::{
Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, Shr, Sub, SubAssign,
};
/// A meta trait for arithmetic type operations, regardless of any limitation on size.
@@ -86,13 +86,13 @@ pub enum Error {
CannotSign(Vec<u8>, String),
}
impl core::convert::From<Public> for Error {
impl From<Public> for Error {
fn from(p: Public) -> Self {
Self::InvalidAuthority(p)
}
}
impl core::convert::From<String> for Error {
impl From<String> for Error {
fn from(s: String) -> Self {
Self::StateUnavailable(s)
}
@@ -21,7 +21,6 @@ use codec::{Decode, Encode, EncodeLike};
use schnorrkel::errors::MultiSignatureStage;
use sp_core::U512;
use sp_std::{
convert::TryFrom,
ops::{Deref, DerefMut},
prelude::*,
};
+2 -2
View File
@@ -38,7 +38,7 @@ pub use secrecy::SecretString;
use sp_runtime_interface::pass_by::PassByInner;
#[doc(hidden)]
pub use sp_std::ops::Deref;
use sp_std::{convert::TryFrom, hash::Hash, str, vec::Vec};
use sp_std::{hash::Hash, str, vec::Vec};
/// Trait to zeroize a memory buffer.
pub use zeroize::Zeroize;
@@ -535,7 +535,7 @@ impl From<[u8; 32]> for AccountId32 {
}
}
impl<'a> sp_std::convert::TryFrom<&'a [u8]> for AccountId32 {
impl<'a> TryFrom<&'a [u8]> for AccountId32 {
type Error = ();
fn try_from(x: &'a [u8]) -> Result<AccountId32, ()> {
if x.len() == 32 {
+2 -2
View File
@@ -137,7 +137,7 @@ impl AsMut<[u8]> for Public {
}
}
impl sp_std::convert::TryFrom<&[u8]> for Public {
impl TryFrom<&[u8]> for Public {
type Error = ();
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
@@ -209,7 +209,7 @@ impl<'de> Deserialize<'de> for Public {
#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq)]
pub struct Signature(pub [u8; 65]);
impl sp_std::convert::TryFrom<&[u8]> for Signature {
impl TryFrom<&[u8]> for Signature {
type Error = ();
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
+2 -4
View File
@@ -39,8 +39,6 @@ use crate::crypto::{DeriveJunction, Pair as TraitPair, SecretStringError};
#[cfg(feature = "std")]
use bip39::{Language, Mnemonic, MnemonicType};
#[cfg(feature = "full_crypto")]
use core::convert::TryFrom;
#[cfg(feature = "full_crypto")]
use ed25519_dalek::{Signer as _, Verifier as _};
#[cfg(feature = "std")]
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
@@ -116,7 +114,7 @@ impl Deref for Public {
}
}
impl sp_std::convert::TryFrom<&[u8]> for Public {
impl TryFrom<&[u8]> for Public {
type Error = ();
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
@@ -215,7 +213,7 @@ impl<'de> Deserialize<'de> for Public {
#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq)]
pub struct Signature(pub [u8; 64]);
impl sp_std::convert::TryFrom<&[u8]> for Signature {
impl TryFrom<&[u8]> for Signature {
type Error = ();
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
@@ -21,10 +21,7 @@ use crate::{OpaquePeerId, RuntimeDebug};
use codec::{Decode, Encode};
use scale_info::TypeInfo;
use sp_runtime_interface::pass_by::{PassByCodec, PassByEnum, PassByInner};
use sp_std::{
convert::TryFrom,
prelude::{Box, Vec},
};
use sp_std::prelude::{Box, Vec};
pub use crate::crypto::KeyTypeId;
+2 -4
View File
@@ -35,8 +35,6 @@ use schnorrkel::{
#[cfg(feature = "full_crypto")]
use sp_std::vec::Vec;
#[cfg(feature = "std")]
use std::convert::TryFrom;
#[cfg(feature = "std")]
use substrate_bip39::mini_secret_from_entropy;
use crate::{
@@ -142,7 +140,7 @@ impl std::str::FromStr for Public {
}
}
impl sp_std::convert::TryFrom<&[u8]> for Public {
impl TryFrom<&[u8]> for Public {
type Error = ();
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
@@ -215,7 +213,7 @@ impl<'de> Deserialize<'de> for Public {
#[derive(Encode, Decode, MaxEncodedLen, PassByInner, TypeInfo, PartialEq, Eq)]
pub struct Signature(pub [u8; 64]);
impl sp_std::convert::TryFrom<&[u8]> for Signature {
impl TryFrom<&[u8]> for Signature {
type Error = ();
fn try_from(data: &[u8]) -> Result<Self, Self::Error> {
+1 -4
View File
@@ -20,10 +20,7 @@
use serde::{Deserialize, Serialize};
use sp_core::U256;
use std::{
convert::{TryFrom, TryInto},
fmt::Debug,
};
use std::fmt::Debug;
/// A number type that can be serialized both as a number or a string that encodes a number in a
/// string.
@@ -51,7 +51,7 @@ pub fn derive_impl(input: DeriveInput) -> Result<TokenStream> {
type PassBy = #crate_::pass_by::Enum<#ident>;
}
impl #crate_::sp_std::convert::TryFrom<u8> for #ident {
impl TryFrom<u8> for #ident {
type Error = ();
fn try_from(inner: u8) -> #crate_::sp_std::result::Result<Self, ()> {
@@ -33,7 +33,7 @@ use crate::wasm::*;
#[cfg(feature = "std")]
use sp_wasm_interface::{FunctionContext, Pointer, Result};
use sp_std::{convert::TryFrom, marker::PhantomData};
use sp_std::marker::PhantomData;
#[cfg(not(feature = "std"))]
use sp_std::vec::Vec;
@@ -382,7 +382,7 @@ impl<T: PassByInner<Inner = I>, I: RIType> RIType for Inner<T, I> {
/// }
/// }
///
/// impl std::convert::TryFrom<u8> for Test {
/// impl TryFrom<u8> for Test {
/// type Error = ();
///
/// fn try_from(val: u8) -> Result<Test, ()> {
@@ -22,7 +22,7 @@
use sp_runtime_interface::runtime_interface;
#[cfg(not(feature = "std"))]
use sp_std::{convert::TryFrom, mem, prelude::*};
use sp_std::{mem, prelude::*};
use sp_core::{sr25519::Public, wasm_export_functions};
@@ -110,8 +110,6 @@ where
#[test]
fn test_multiply_by_rational_saturating() {
use std::convert::TryInto;
let div = 100u32;
for value in 0..=div {
for p in 0..=div {
@@ -132,8 +130,6 @@ fn test_multiply_by_rational_saturating() {
#[test]
fn test_calculate_for_fraction_times_denominator() {
use std::convert::TryInto;
let curve = PiecewiseLinear {
points: &[
(Perbill::from_parts(0_000_000_000), Perbill::from_parts(0_500_000_000)),
@@ -29,7 +29,7 @@ use crate::{
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::U256;
use sp_std::{convert::TryFrom, fmt::Debug};
use sp_std::fmt::Debug;
/// Abstraction over a block header for a substrate chain.
#[derive(Encode, Decode, PartialEq, Eq, Clone, sp_core::RuntimeDebug, TypeInfo)]
+1 -1
View File
@@ -50,7 +50,7 @@ use sp_core::{
hash::{H256, H512},
sr25519,
};
use sp_std::{convert::TryFrom, prelude::*};
use sp_std::prelude::*;
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
+1 -7
View File
@@ -37,13 +37,7 @@ pub use sp_arithmetic::traits::{
UniqueSaturatedFrom, UniqueSaturatedInto, Zero,
};
use sp_core::{self, storage::StateVersion, Hasher, RuntimeDebug, TypeId};
use sp_std::{
self,
convert::{TryFrom, TryInto},
fmt::Debug,
marker::PhantomData,
prelude::*,
};
use sp_std::{self, fmt::Debug, marker::PhantomData, prelude::*};
#[cfg(feature = "std")]
use std::fmt::Display;
#[cfg(feature = "std")]
-1
View File
@@ -103,7 +103,6 @@ pub mod prelude {
boxed::Box,
clone::Clone,
cmp::{Eq, PartialEq, Reverse},
convert::{TryFrom, TryInto},
iter::IntoIterator,
vec::Vec,
};
+1 -1
View File
@@ -423,7 +423,7 @@ impl From<StateVersion> for u8 {
}
}
impl sp_std::convert::TryFrom<u8> for StateVersion {
impl TryFrom<u8> for StateVersion {
type Error = ();
fn try_from(val: u8) -> sp_std::result::Result<StateVersion, ()> {
match val {
@@ -73,7 +73,7 @@ impl From<ValueType> for u8 {
}
}
impl sp_std::convert::TryFrom<u8> for ValueType {
impl TryFrom<u8> for ValueType {
type Error = ();
fn try_from(val: u8) -> sp_std::result::Result<ValueType, ()> {