Skip to content

Commit

Permalink
sp-std -> core (paritytech#3199)
Browse files Browse the repository at this point in the history
First in a series of PRs that reduces our use of sp-std with a view to
deprecating it.

This is just looking at /substrate and moving some of the references
from `sp-std` to `core`.
These particular changes should be uncontroversial.

Where macros are used `::core` should be used to remove any ambiguity.

part of paritytech#2101
  • Loading branch information
gilescope authored Feb 6, 2024
1 parent 6ad2d32 commit a58f04e
Show file tree
Hide file tree
Showing 75 changed files with 125 additions and 125 deletions.
5 changes: 2 additions & 3 deletions substrate/frame/alliance/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
#![cfg(feature = "runtime-benchmarks")]

use sp_runtime::traits::{Bounded, Hash, StaticLookup};
use sp_std::{
use core::{
cmp,
convert::{TryFrom, TryInto},
mem::size_of,
prelude::*,
};
use sp_runtime::traits::{Bounded, Hash, StaticLookup};

use frame_benchmarking::{account, impl_benchmark_test_suite, v2::*, BenchmarkError};
use frame_support::traits::{EnsureOrigin, Get, UnfilteredDispatchable};
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/alliance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

//! Test utilities
use core::convert::{TryFrom, TryInto};
pub use sp_core::H256;
use sp_runtime::traits::Hash;
pub use sp_runtime::{
traits::{BlakeTwo256, IdentifyAccount, Lazy, Verify},
BuildStorage,
};
use sp_std::convert::{TryFrom, TryInto};

pub use frame_support::{
assert_noop, assert_ok, derive_impl, ord_parameter_types, parameter_types,
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/asset-conversion/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use super::*;
use crate as pallet_asset_conversion;
use core::default::Default;
use frame_support::{
construct_runtime, derive_impl,
instances::{Instance1, Instance2},
Expand All @@ -39,7 +40,6 @@ use sp_runtime::{
traits::{AccountIdConversion, BlakeTwo256, IdentityLookup},
BuildStorage,
};
use sp_std::default::Default;

type Block = frame_system::mocking::MockBlock<Test>;

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/asset-conversion/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

use super::*;
use codec::{Decode, Encode, MaxEncodedLen};
use core::marker::PhantomData;
use scale_info::TypeInfo;
use sp_std::marker::PhantomData;

/// Represents a swap path with associated asset amounts indicating how much of the asset needs to
/// be deposited to get the following asset's amount withdrawn (this is inclusive of fees).
Expand Down
6 changes: 3 additions & 3 deletions substrate/frame/assets/src/extra_mutator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<T: Config<I>, I: 'static> Drop for ExtraMutator<T, I> {
}
}

impl<T: Config<I>, I: 'static> sp_std::ops::Deref for ExtraMutator<T, I> {
impl<T: Config<I>, I: 'static> core::ops::Deref for ExtraMutator<T, I> {
type Target = T::Extra;
fn deref(&self) -> &T::Extra {
match self.pending {
Expand All @@ -48,7 +48,7 @@ impl<T: Config<I>, I: 'static> sp_std::ops::Deref for ExtraMutator<T, I> {
}
}

impl<T: Config<I>, I: 'static> sp_std::ops::DerefMut for ExtraMutator<T, I> {
impl<T: Config<I>, I: 'static> core::ops::DerefMut for ExtraMutator<T, I> {
fn deref_mut(&mut self) -> &mut T::Extra {
if self.pending.is_none() {
self.pending = Some(self.original.clone());
Expand All @@ -60,7 +60,7 @@ impl<T: Config<I>, I: 'static> sp_std::ops::DerefMut for ExtraMutator<T, I> {
impl<T: Config<I>, I: 'static> ExtraMutator<T, I> {
pub(super) fn maybe_new(
id: T::AssetId,
who: impl sp_std::borrow::Borrow<T::AccountId>,
who: impl core::borrow::Borrow<T::AccountId>,
) -> Option<ExtraMutator<T, I>> {
if let Some(a) = Account::<T, I>::get(&id, who.borrow()) {
Some(ExtraMutator::<T, I> {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/assets/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub mod v1 {
}
}

pub struct MigrateToV1<T>(sp_std::marker::PhantomData<T>);
pub struct MigrateToV1<T>(core::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> {
fn on_runtime_upgrade() -> Weight {
let current_version = Pallet::<T>::current_storage_version();
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/assets/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ where
return None
}
if let ExistenceReason::DepositHeld(deposit) =
sp_std::mem::replace(self, ExistenceReason::DepositRefunded)
core::mem::replace(self, ExistenceReason::DepositRefunded)
{
Some(deposit)
} else {
Expand All @@ -136,7 +136,7 @@ where
return None
}
if let ExistenceReason::DepositFrom(depositor, deposit) =
sp_std::mem::replace(self, ExistenceReason::DepositRefunded)
core::mem::replace(self, ExistenceReason::DepositRefunded)
{
Some((depositor, deposit))
} else {
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/atomic-swap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
mod tests;

use codec::{Decode, Encode};
use core::{
marker::PhantomData,
ops::{Deref, DerefMut},
};
use frame_support::{
dispatch::DispatchResult,
pallet_prelude::MaxEncodedLen,
Expand All @@ -54,11 +58,6 @@ use frame_system::pallet_prelude::BlockNumberFor;
use scale_info::TypeInfo;
use sp_io::hashing::blake2_256;
use sp_runtime::RuntimeDebug;
use sp_std::{
marker::PhantomData,
ops::{Deref, DerefMut},
prelude::*,
};

/// Pending atomic swap operation.
#[derive(Clone, Eq, PartialEq, RuntimeDebugNoBound, Encode, Decode, TypeInfo, MaxEncodedLen)]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/aura/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use frame_support::{pallet_prelude::*, traits::Get, weights::Weight};

struct __LastTimestamp<T>(sp_std::marker::PhantomData<T>);
struct __LastTimestamp<T>(core::marker::PhantomData<T>);
impl<T: RemoveLastTimestamp> frame_support::traits::StorageInstance for __LastTimestamp<T> {
fn pallet_prefix() -> &'static str {
T::PalletPrefix::get()
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/babe/src/randomness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use sp_runtime::traits::{Hash, One, Saturating};
///
/// Adversaries should not possess many block production slots towards the beginning or
/// end of every epoch, but they possess some influence over when they possess more slots.
pub struct RandomnessFromTwoEpochsAgo<T>(sp_std::marker::PhantomData<T>);
pub struct RandomnessFromTwoEpochsAgo<T>(core::marker::PhantomData<T>);

/// Randomness usable by on-chain code that **does not depend** upon finality and takes
/// action based upon on-chain commitments made during the previous epoch.
Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct RandomnessFromTwoEpochsAgo<T>(sp_std::marker::PhantomData<T>);
/// As an example usage, we determine parachain auctions ending times in Polkadot using
/// `RandomnessFromOneEpochAgo` because it reduces bias from `ParentBlockRandomness` and
/// does not require the extra finality delay of `RandomnessFromTwoEpochsAgo`.
pub struct RandomnessFromOneEpochAgo<T>(sp_std::marker::PhantomData<T>);
pub struct RandomnessFromOneEpochAgo<T>(core::marker::PhantomData<T>);

/// Randomness produced semi-freshly with each block, but inherits limitations of
/// `RandomnessFromTwoEpochsAgo` from which it derives.
Expand Down Expand Up @@ -119,7 +119,7 @@ pub struct RandomnessFromOneEpochAgo<T>(sp_std::marker::PhantomData<T>);
/// instead you are using this randomness externally, i.e. after block execution, then
/// this randomness will be provided by the "current" block (this stems from the fact that
/// we process VRF outputs on block execution finalization, i.e. `on_finalize`).
pub struct ParentBlockRandomness<T>(sp_std::marker::PhantomData<T>);
pub struct ParentBlockRandomness<T>(core::marker::PhantomData<T>);

/// Randomness produced semi-freshly with each block, but inherits limitations of
/// `RandomnessFromTwoEpochsAgo` from which it derives.
Expand All @@ -128,7 +128,7 @@ pub struct ParentBlockRandomness<T>(sp_std::marker::PhantomData<T>);
#[deprecated(note = "Should not be relied upon for correctness, \
will not provide fresh randomness for the current block. \
Please use `ParentBlockRandomness` instead.")]
pub struct CurrentBlockRandomness<T>(sp_std::marker::PhantomData<T>);
pub struct CurrentBlockRandomness<T>(core::marker::PhantomData<T>);

impl<T: Config> RandomnessT<T::Hash, BlockNumberFor<T>> for RandomnessFromTwoEpochsAgo<T> {
fn random(subject: &[u8]) -> (T::Hash, BlockNumberFor<T>) {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/bounties/src/migrations/v4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use core::str;
use frame_support::{
storage::{generator::StorageValue, StoragePrefixedMap},
traits::{
Expand All @@ -25,7 +26,6 @@ use frame_support::{
};
use sp_core::hexdisplay::HexDisplay;
use sp_io::{hashing::twox_128, storage};
use sp_std::str;

use crate as pallet_bounties;

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/collective/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use super::*;
use crate::Pallet as Collective;

use core::mem::size_of;
use sp_runtime::traits::Bounded;
use sp_std::mem::size_of;

use frame_benchmarking::v1::{account, benchmarks_instance_pallet, whitelisted_caller};
use frame_system::{
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/contracts/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
// limitations under the License.

use crate::{exec::ExecError, Config, Error};
use core::marker::PhantomData;
use frame_support::{
dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, PostDispatchInfo},
weights::Weight,
DefaultNoBound,
};
use sp_core::Get;
use sp_runtime::{traits::Zero, DispatchError};
use sp_std::marker::PhantomData;

#[cfg(test)]
use std::{any::Any, fmt::Debug};
Expand Down
7 changes: 5 additions & 2 deletions substrate/frame/contracts/src/migration/v10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use crate::{
CodeHash, Config, Pallet, TrieId, Weight, LOG_TARGET,
};
use codec::{Decode, Encode};
use core::cmp::{max, min};
use core::{
cmp::{max, min},
ops::Deref,
};
use frame_support::{
pallet_prelude::*,
storage_alias,
Expand All @@ -42,7 +45,7 @@ use sp_runtime::{
traits::{Hash, TrailingZeroInput, Zero},
Perbill, Saturating,
};
use sp_std::{ops::Deref, prelude::*};
use sp_std::prelude::*;

mod old {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/contracts/src/schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
use crate::{weights::WeightInfo, Config};

use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::{weights::Weight, DefaultNoBound};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_std::marker::PhantomData;

/// Definition of the cost schedule and other parameterizations for the wasm vm.
///
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/core-fellowship/src/tests/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use std::collections::BTreeMap;

use core::cell::RefCell;
use frame_support::{
assert_noop, assert_ok, derive_impl, ord_parameter_types,
pallet_prelude::Weight,
Expand All @@ -27,7 +28,6 @@ use frame_support::{
};
use frame_system::EnsureSignedBy;
use sp_runtime::{traits::TryMorphInto, BuildStorage, DispatchError, DispatchResult};
use sp_std::cell::RefCell;

use crate as pallet_core_fellowship;
use crate::*;
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/democracy/src/conviction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
use crate::types::Delegations;
use codec::{Decode, Encode, MaxEncodedLen};
use core::result::Result;
use scale_info::TypeInfo;
use sp_runtime::{
traits::{Bounded, CheckedDiv, CheckedMul, Zero},
RuntimeDebug,
};
use sp_std::{prelude::*, result::Result};

/// A value denoting the strength of conviction of a vote.
#[derive(
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/democracy/src/migrations/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub mod v1 {
use super::*;

/// Migration for translating bare `Hash`es into `Bounded<Call>`s.
pub struct Migration<T>(sp_std::marker::PhantomData<T>);
pub struct Migration<T>(core::marker::PhantomData<T>);

impl<T: Config + frame_system::Config<Hash = H256>> OnRuntimeUpgrade for Migration<T> {
#[cfg(feature = "try-runtime")]
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/democracy/src/vote_threshold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
use crate::Tally;
use codec::{Decode, Encode, MaxEncodedLen};
use core::ops::{Add, Div, Mul, Rem};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::traits::{IntegerSquareRoot, Zero};
use sp_std::ops::{Add, Div, Mul, Rem};

/// A means of determining if a vote is past pass threshold.
#[derive(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ frame_benchmarking::benchmarks! {
let (_, stake, _) = voters[*idx];
stake
}).unwrap_or_default();
sp_std::cmp::Reverse(stake)
core::cmp::Reverse(stake)
});

let mut index_assignments = assignments
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/election-provider-support/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod solution_type {
// these need to come from the same dev-dependency `frame-election-provider-support`, not from
// the crate.
use crate::{generate_solution_type, Assignment, Error as NposError, NposSolution};
use sp_std::fmt::Debug;
use core::fmt::Debug;

#[allow(dead_code)]
mod __private {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/election-provider-support/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions substrate/frame/examples/basic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode};
use core::marker::PhantomData;
use frame_support::{
dispatch::{ClassifyDispatch, DispatchClass, DispatchResult, Pays, PaysFee, WeighData},
traits::IsSubType,
Expand All @@ -68,7 +69,7 @@ use sp_runtime::{
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,
},
};
use sp_std::{marker::PhantomData, prelude::*};
use sp_std::vec::Vec;

// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;
Expand Down Expand Up @@ -485,8 +486,8 @@ impl<T: Config> Pallet<T> {
#[scale_info(skip_type_params(T))]
pub struct WatchDummy<T: Config + Send + Sync>(PhantomData<T>);

impl<T: Config + Send + Sync> sp_std::fmt::Debug for WatchDummy<T> {
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
impl<T: Config + Send + Sync> core::fmt::Debug for WatchDummy<T> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "WatchDummy")
}
}
Expand All @@ -501,7 +502,7 @@ where
type AdditionalSigned = ();
type Pre = ();

fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
fn additional_signed(&self) -> core::result::Result<(), TransactionValidityError> {
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/examples/basic/src/weights.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion substrate/frame/grandpa/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ mod v5;
/// This migration should be added with a runtime upgrade that introduces the
/// `MaxSetIdSessionEntries` constant to the pallet (although it could also be
/// done later on).
pub struct CleanupSetIdSessionMap<T>(sp_std::marker::PhantomData<T>);
pub struct CleanupSetIdSessionMap<T>(core::marker::PhantomData<T>);
impl<T: Config> OnRuntimeUpgrade for CleanupSetIdSessionMap<T> {
fn on_runtime_upgrade() -> Weight {
// NOTE: since this migration will loop over all stale entries in the
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/im-online/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub mod v1 {
use super::*;

/// Simple migration that replaces `ReceivedHeartbeats` values with `true`.
pub struct Migration<T>(sp_std::marker::PhantomData<T>);
pub struct Migration<T>(core::marker::PhantomData<T>);

impl<T: Config> OnRuntimeUpgrade for Migration<T> {
#[cfg(feature = "try-runtime")]
Expand Down
Loading

0 comments on commit a58f04e

Please sign in to comment.