From c139739868eddbda495d642219a57602f63c18f5 Mon Sep 17 00:00:00 2001
From: Jeeyong Um <conr2d@proton.me>
Date: Tue, 7 Jan 2025 15:57:06 +0800
Subject: [PATCH] Remove usage of `sp-std` from Substrate (#7043)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

# Description

This PR removes usage of deprecated `sp-std` from Substrate. (following
PR of #5010)

## Integration

This PR doesn't remove re-exported `sp_std` from any crates yet, so
downstream projects using re-exported `sp_std` will not be affected.

## Review Notes

The existing code using `sp-std` is refactored to use `alloc` and `core`
directly. The key-value maps are instantiated from a vector of tuples
directly instead of using `sp_std::map!` macro.

`sp_std::Writer` is a helper type to use `Vec<u8>` with
`core::fmt::Write` trait. This PR copied it into `sp-runtime`, because
all crates using `sp_std::Writer` (including `sp-runtime` itself,
`frame-support`, etc.) depend on `sp-runtime`.

If this PR is merged, I would write following PRs to remove remaining
usage of `sp-std` from `bridges` and `cumulus`.

---------

Co-authored-by: command-bot <>
Co-authored-by: Guillaume Thiolliere <guillaume.thiolliere@parity.io>
Co-authored-by: Bastian Köcher <info@kchr.de>
Co-authored-by: Bastian Köcher <git@kchr.de>
---
 Cargo.lock                                    | 11 ----
 prdoc/pr_7043.prdoc                           | 51 +++++++++++++++++++
 substrate/client/sysinfo/Cargo.toml           |  1 -
 .../frame/bags-list/remote-tests/Cargo.toml   |  1 -
 substrate/frame/contracts/Cargo.toml          |  2 -
 .../frame/contracts/proc-macro/src/lib.rs     |  7 ++-
 .../frame/contracts/src/transient_storage.rs  |  4 +-
 .../test-staking-e2e/Cargo.toml               |  1 -
 .../frame/nft-fractionalization/Cargo.toml    |  1 -
 .../test-delegate-stake/Cargo.toml            |  1 -
 .../test-transfer-stake/Cargo.toml            |  1 -
 substrate/frame/revive/Cargo.toml             |  2 -
 substrate/frame/revive/proc-macro/src/lib.rs  |  7 ++-
 .../frame/revive/src/transient_storage.rs     |  4 +-
 substrate/frame/root-offences/Cargo.toml      |  1 -
 .../procedural/src/pallet/expand/config.rs    |  6 +--
 substrate/frame/support/src/lib.rs            |  7 +--
 substrate/frame/system/Cargo.toml             |  2 -
 substrate/frame/system/src/lib.rs             | 16 +++---
 substrate/frame/uniques/Cargo.toml            |  1 -
 .../src/generic/unchecked_extrinsic.rs        |  2 +-
 .../runtime/src/proving_trie/base16.rs        |  4 +-
 .../runtime/src/proving_trie/base2.rs         |  4 +-
 .../runtime/src/proving_trie/mod.rs           |  2 +-
 .../primitives/runtime/src/runtime_logger.rs  |  6 +--
 .../primitives/runtime/src/traits/mod.rs      |  2 +-
 .../src/traits/transaction_extension/mod.rs   | 11 ++--
 27 files changed, 92 insertions(+), 66 deletions(-)
 create mode 100644 prdoc/pr_7043.prdoc

diff --git a/Cargo.lock b/Cargo.lock
index b0fb0586be3..ef0eb9f7e3d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -7716,7 +7716,6 @@ dependencies = [
  "sp-externalities 0.25.0",
  "sp-io 30.0.0",
  "sp-runtime 31.0.1",
- "sp-std 14.0.0",
  "sp-version 29.0.0",
  "sp-weights 27.0.0",
  "substrate-test-runtime-client",
@@ -12371,7 +12370,6 @@ dependencies = [
  "pallet-staking 28.0.0",
  "sp-core 28.0.0",
  "sp-runtime 31.0.1",
- "sp-std 14.0.0",
  "sp-storage 19.0.0",
  "sp-tracing 16.0.0",
 ]
@@ -12967,7 +12965,6 @@ dependencies = [
  "sp-io 30.0.0",
  "sp-keystore 0.34.0",
  "sp-runtime 31.0.1",
- "sp-std 14.0.0",
  "sp-tracing 16.0.0",
  "staging-xcm 7.0.0",
  "staging-xcm-builder 7.0.0",
@@ -13352,7 +13349,6 @@ dependencies = [
  "sp-npos-elections 26.0.0",
  "sp-runtime 31.0.1",
  "sp-staking 26.0.0",
- "sp-std 14.0.0",
  "sp-tracing 16.0.0",
 ]
 
@@ -14157,7 +14153,6 @@ dependencies = [
  "sp-core 28.0.0",
  "sp-io 30.0.0",
  "sp-runtime 31.0.1",
- "sp-std 14.0.0",
 ]
 
 [[package]]
@@ -14432,7 +14427,6 @@ dependencies = [
  "sp-io 30.0.0",
  "sp-runtime 31.0.1",
  "sp-staking 26.0.0",
- "sp-std 14.0.0",
  "sp-tracing 16.0.0",
 ]
 
@@ -14456,7 +14450,6 @@ dependencies = [
  "sp-io 30.0.0",
  "sp-runtime 31.0.1",
  "sp-staking 26.0.0",
- "sp-std 14.0.0",
  "sp-tracing 16.0.0",
 ]
 
@@ -14870,7 +14863,6 @@ dependencies = [
  "sp-io 30.0.0",
  "sp-keystore 0.34.0",
  "sp-runtime 31.0.1",
- "sp-std 14.0.0",
  "sp-tracing 16.0.0",
  "staging-xcm 7.0.0",
  "staging-xcm-builder 7.0.0",
@@ -15095,7 +15087,6 @@ dependencies = [
  "sp-io 30.0.0",
  "sp-runtime 31.0.1",
  "sp-staking 26.0.0",
- "sp-std 14.0.0",
 ]
 
 [[package]]
@@ -15941,7 +15932,6 @@ dependencies = [
  "sp-core 28.0.0",
  "sp-io 30.0.0",
  "sp-runtime 31.0.1",
- "sp-std 14.0.0",
 ]
 
 [[package]]
@@ -23681,7 +23671,6 @@ dependencies = [
  "sp-crypto-hashing 0.1.0",
  "sp-io 30.0.0",
  "sp-runtime 31.0.1",
- "sp-std 14.0.0",
 ]
 
 [[package]]
diff --git a/prdoc/pr_7043.prdoc b/prdoc/pr_7043.prdoc
new file mode 100644
index 00000000000..d7f6cd6907c
--- /dev/null
+++ b/prdoc/pr_7043.prdoc
@@ -0,0 +1,51 @@
+title: Remove usage of `sp-std` from Substrate
+doc:
+- audience: Runtime Dev
+  description: |-
+    # Description
+
+    This PR removes usage of deprecated `sp-std` from Substrate. (following PR of #5010)
+
+    ## Integration
+
+    This PR doesn't remove re-exported `sp_std` from any crates yet, so downstream projects using re-exported `sp_std` will not be affected.
+
+    ## Review Notes
+
+    The existing code using `sp-std` is refactored to use `alloc` and `core` directly. The key-value maps are instantiated from an array of tuples directly instead of using `sp_std::map!` macro.
+
+    This PR replaces `sp_std::Writer`, a helper type for using `Vec<u8>` with `core::fmt::Write` trait, with `alloc::string::String`.
+
+crates:
+- name: pallet-contracts
+  bump: patch
+- name: pallet-revive
+  bump: patch
+- name: sp-runtime
+  bump: patch
+- name: frame-support-procedural
+  bump: patch
+- name: frame-system
+  bump: patch
+- name: pallet-contracts-proc-macro
+  bump: patch
+- name: pallet-revive-proc-macro
+  bump: patch
+- name: frame-support
+  bump: patch
+- name: sc-sysinfo
+  bump: patch
+- name: pallet-bags-list-remote-tests
+  bump: patch
+- name: pallet-election-provider-e2e-test
+  bump: patch
+- name: pallet-nft-fractionalization
+  bump: patch
+- name: pallet-nomination-pools-test-delegate-stake
+  bump: patch
+- name: pallet-nomination-pools-test-transfer-stake
+  bump: patch
+- name: pallet-root-offences
+  bump: patch
+- name: pallet-uniques
+  bump: patch
diff --git a/substrate/client/sysinfo/Cargo.toml b/substrate/client/sysinfo/Cargo.toml
index c7eed77eda7..afc464c3588 100644
--- a/substrate/client/sysinfo/Cargo.toml
+++ b/substrate/client/sysinfo/Cargo.toml
@@ -30,7 +30,6 @@ serde_json = { workspace = true, default-features = true }
 sp-core = { workspace = true, default-features = true }
 sp-crypto-hashing = { workspace = true, default-features = true }
 sp-io = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
 
 [dev-dependencies]
 sp-runtime = { workspace = true, default-features = true }
diff --git a/substrate/frame/bags-list/remote-tests/Cargo.toml b/substrate/frame/bags-list/remote-tests/Cargo.toml
index 99b203e73fb..e3215803a02 100644
--- a/substrate/frame/bags-list/remote-tests/Cargo.toml
+++ b/substrate/frame/bags-list/remote-tests/Cargo.toml
@@ -26,7 +26,6 @@ pallet-staking = { workspace = true, default-features = true }
 # core
 sp-core = { workspace = true, default-features = true }
 sp-runtime = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
 sp-storage = { workspace = true, default-features = true }
 sp-tracing = { workspace = true, default-features = true }
 
diff --git a/substrate/frame/contracts/Cargo.toml b/substrate/frame/contracts/Cargo.toml
index e39128639e3..5784e6dd155 100644
--- a/substrate/frame/contracts/Cargo.toml
+++ b/substrate/frame/contracts/Cargo.toml
@@ -50,7 +50,6 @@ sp-api = { workspace = true }
 sp-core = { workspace = true }
 sp-io = { workspace = true }
 sp-runtime = { workspace = true }
-sp-std = { workspace = true }
 
 xcm = { workspace = true }
 xcm-builder = { workspace = true }
@@ -98,7 +97,6 @@ std = [
 	"sp-io/std",
 	"sp-keystore/std",
 	"sp-runtime/std",
-	"sp-std/std",
 	"wasm-instrument?/std",
 	"wasmi/std",
 	"xcm-builder/std",
diff --git a/substrate/frame/contracts/proc-macro/src/lib.rs b/substrate/frame/contracts/proc-macro/src/lib.rs
index 4aba1d24dbd..5c3c34e6ef3 100644
--- a/substrate/frame/contracts/proc-macro/src/lib.rs
+++ b/substrate/frame/contracts/proc-macro/src/lib.rs
@@ -650,10 +650,9 @@ fn expand_functions(def: &EnvDef, expand_mode: ExpandMode) -> TokenStream2 {
 				let result = #body;
 				if ::log::log_enabled!(target: "runtime::contracts::strace", ::log::Level::Trace) {
 						use core::fmt::Write;
-						let mut w = sp_std::Writer::default();
-						let _ = core::write!(&mut w, #trace_fmt_str, #( #trace_fmt_args, )* result);
-						let msg = core::str::from_utf8(&w.inner()).unwrap_or_default();
-						ctx.ext().append_debug_buffer(msg);
+						let mut msg = alloc::string::String::default();
+						let _ = core::write!(&mut msg, #trace_fmt_str, #( #trace_fmt_args, )* result);
+						ctx.ext().append_debug_buffer(&msg);
 				}
 				result
 			}
diff --git a/substrate/frame/contracts/src/transient_storage.rs b/substrate/frame/contracts/src/transient_storage.rs
index c795a966385..c9b1dac1ad7 100644
--- a/substrate/frame/contracts/src/transient_storage.rs
+++ b/substrate/frame/contracts/src/transient_storage.rs
@@ -22,11 +22,11 @@ use crate::{
 	storage::WriteOutcome,
 	Config, Error,
 };
+use alloc::{collections::BTreeMap, vec::Vec};
 use codec::Encode;
-use core::marker::PhantomData;
+use core::{marker::PhantomData, mem};
 use frame_support::DefaultNoBound;
 use sp_runtime::{DispatchError, DispatchResult, Saturating};
-use sp_std::{collections::btree_map::BTreeMap, mem, vec::Vec};
 
 /// Meter entry tracks transaction allocations.
 #[derive(Default, Debug)]
diff --git a/substrate/frame/election-provider-multi-phase/test-staking-e2e/Cargo.toml b/substrate/frame/election-provider-multi-phase/test-staking-e2e/Cargo.toml
index 5009d3d54d5..7a48ae868a5 100644
--- a/substrate/frame/election-provider-multi-phase/test-staking-e2e/Cargo.toml
+++ b/substrate/frame/election-provider-multi-phase/test-staking-e2e/Cargo.toml
@@ -26,7 +26,6 @@ sp-io = { workspace = true, default-features = true }
 sp-npos-elections = { workspace = true }
 sp-runtime = { workspace = true, default-features = true }
 sp-staking = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
 sp-tracing = { workspace = true, default-features = true }
 
 frame-election-provider-support = { workspace = true, default-features = true }
diff --git a/substrate/frame/nft-fractionalization/Cargo.toml b/substrate/frame/nft-fractionalization/Cargo.toml
index 7f6df86ed0e..23537b22789 100644
--- a/substrate/frame/nft-fractionalization/Cargo.toml
+++ b/substrate/frame/nft-fractionalization/Cargo.toml
@@ -30,7 +30,6 @@ sp-runtime = { workspace = true }
 pallet-balances = { workspace = true, default-features = true }
 sp-core = { workspace = true, default-features = true }
 sp-io = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
 
 [features]
 default = ["std"]
diff --git a/substrate/frame/nomination-pools/test-delegate-stake/Cargo.toml b/substrate/frame/nomination-pools/test-delegate-stake/Cargo.toml
index fe3743d7e5d..62c2fb625fc 100644
--- a/substrate/frame/nomination-pools/test-delegate-stake/Cargo.toml
+++ b/substrate/frame/nomination-pools/test-delegate-stake/Cargo.toml
@@ -23,7 +23,6 @@ sp-core = { workspace = true, default-features = true }
 sp-io = { workspace = true, default-features = true }
 sp-runtime = { workspace = true, default-features = true }
 sp-staking = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
 
 frame-election-provider-support = { workspace = true, default-features = true }
 frame-support = { features = ["experimental"], workspace = true, default-features = true }
diff --git a/substrate/frame/nomination-pools/test-transfer-stake/Cargo.toml b/substrate/frame/nomination-pools/test-transfer-stake/Cargo.toml
index 2cdc4c41a08..0b21d5f4e8c 100644
--- a/substrate/frame/nomination-pools/test-transfer-stake/Cargo.toml
+++ b/substrate/frame/nomination-pools/test-transfer-stake/Cargo.toml
@@ -23,7 +23,6 @@ sp-core = { workspace = true, default-features = true }
 sp-io = { workspace = true, default-features = true }
 sp-runtime = { workspace = true, default-features = true }
 sp-staking = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
 
 frame-election-provider-support = { workspace = true, default-features = true }
 frame-support = { workspace = true, default-features = true }
diff --git a/substrate/frame/revive/Cargo.toml b/substrate/frame/revive/Cargo.toml
index fa008f8e836..1284f5ee894 100644
--- a/substrate/frame/revive/Cargo.toml
+++ b/substrate/frame/revive/Cargo.toml
@@ -46,7 +46,6 @@ sp-arithmetic = { workspace = true }
 sp-core = { workspace = true }
 sp-io = { workspace = true }
 sp-runtime = { workspace = true }
-sp-std = { workspace = true }
 subxt-signer = { workspace = true, optional = true, features = [
 	"unstable-eth",
 ] }
@@ -99,7 +98,6 @@ std = [
 	"sp-io/std",
 	"sp-keystore/std",
 	"sp-runtime/std",
-	"sp-std/std",
 	"subxt-signer",
 	"xcm-builder/std",
 	"xcm/std",
diff --git a/substrate/frame/revive/proc-macro/src/lib.rs b/substrate/frame/revive/proc-macro/src/lib.rs
index b6ea1a06d94..b09bdef1463 100644
--- a/substrate/frame/revive/proc-macro/src/lib.rs
+++ b/substrate/frame/revive/proc-macro/src/lib.rs
@@ -512,10 +512,9 @@ fn expand_functions(def: &EnvDef) -> TokenStream2 {
 				let result = (|| #body)();
 				if ::log::log_enabled!(target: "runtime::revive::strace", ::log::Level::Trace) {
 						use core::fmt::Write;
-						let mut w = sp_std::Writer::default();
-						let _ = core::write!(&mut w, #trace_fmt_str, #( #trace_fmt_args, )* result);
-						let msg = core::str::from_utf8(&w.inner()).unwrap_or_default();
-						self.ext().append_debug_buffer(msg);
+						let mut msg = alloc::string::String::default();
+						let _ = core::write!(&mut msg, #trace_fmt_str, #( #trace_fmt_args, )* result);
+						self.ext().append_debug_buffer(&msg);
 				}
 				result
 			}
diff --git a/substrate/frame/revive/src/transient_storage.rs b/substrate/frame/revive/src/transient_storage.rs
index 298e0296fe6..d88adc43735 100644
--- a/substrate/frame/revive/src/transient_storage.rs
+++ b/substrate/frame/revive/src/transient_storage.rs
@@ -22,11 +22,11 @@ use crate::{
 	storage::WriteOutcome,
 	Config, Error,
 };
+use alloc::{collections::BTreeMap, vec::Vec};
 use codec::Encode;
-use core::marker::PhantomData;
+use core::{marker::PhantomData, mem};
 use frame_support::DefaultNoBound;
 use sp_runtime::{DispatchError, DispatchResult, Saturating};
-use sp_std::{collections::btree_map::BTreeMap, mem, vec::Vec};
 
 /// Meter entry tracks transaction allocations.
 #[derive(Default, Debug)]
diff --git a/substrate/frame/root-offences/Cargo.toml b/substrate/frame/root-offences/Cargo.toml
index dedde9956b6..c539f1dc4dc 100644
--- a/substrate/frame/root-offences/Cargo.toml
+++ b/substrate/frame/root-offences/Cargo.toml
@@ -34,7 +34,6 @@ pallet-timestamp = { workspace = true, default-features = true }
 
 sp-core = { workspace = true, default-features = true }
 sp-io = { workspace = true }
-sp-std = { workspace = true, default-features = true }
 
 frame-election-provider-support = { workspace = true, default-features = true }
 
diff --git a/substrate/frame/support/procedural/src/pallet/expand/config.rs b/substrate/frame/support/procedural/src/pallet/expand/config.rs
index 0a583f1359b..d39f2767236 100644
--- a/substrate/frame/support/procedural/src/pallet/expand/config.rs
+++ b/substrate/frame/support/procedural/src/pallet/expand/config.rs
@@ -126,7 +126,7 @@ pub fn expand_config_metadata(def: &Def) -> proc_macro2::TokenStream {
 				ty: #frame_support::__private::scale_info::meta_type::<
 						<T as Config #trait_use_gen>::#ident
 					>(),
-				docs: #frame_support::__private::sp_std::vec![ #( #doc ),* ],
+				docs: #frame_support::__private::vec![ #( #doc ),* ],
 			}
 		})
 	});
@@ -136,9 +136,9 @@ pub fn expand_config_metadata(def: &Def) -> proc_macro2::TokenStream {
 
 			#[doc(hidden)]
 			pub fn pallet_associated_types_metadata()
-				-> #frame_support::__private::sp_std::vec::Vec<#frame_support::__private::metadata_ir::PalletAssociatedTypeMetadataIR>
+				-> #frame_support::__private::vec::Vec<#frame_support::__private::metadata_ir::PalletAssociatedTypeMetadataIR>
 			{
-				#frame_support::__private::sp_std::vec![ #( #types ),* ]
+				#frame_support::__private::vec![ #( #types ),* ]
 			}
 		}
 	)
diff --git a/substrate/frame/support/src/lib.rs b/substrate/frame/support/src/lib.rs
index c64987b17d3..a6969260e6a 100644
--- a/substrate/frame/support/src/lib.rs
+++ b/substrate/frame/support/src/lib.rs
@@ -44,6 +44,7 @@ pub mod __private {
 	pub use alloc::{
 		boxed::Box,
 		rc::Rc,
+		string::String,
 		vec,
 		vec::{IntoIter, Vec},
 	};
@@ -502,9 +503,9 @@ macro_rules! runtime_print {
 	($($arg:tt)+) => {
 		{
 			use core::fmt::Write;
-			let mut w = $crate::__private::sp_std::Writer::default();
-			let _ = core::write!(&mut w, $($arg)+);
-			$crate::__private::sp_io::misc::print_utf8(&w.inner())
+			let mut msg = $crate::__private::String::default();
+			let _ = core::write!(&mut msg, $($arg)+);
+			$crate::__private::sp_io::misc::print_utf8(msg.as_bytes())
 		}
 	}
 }
diff --git a/substrate/frame/system/Cargo.toml b/substrate/frame/system/Cargo.toml
index 1340b2c55c5..8883ebd4c41 100644
--- a/substrate/frame/system/Cargo.toml
+++ b/substrate/frame/system/Cargo.toml
@@ -26,7 +26,6 @@ serde = { features = ["alloc", "derive"], workspace = true }
 sp-core = { features = ["serde"], workspace = true }
 sp-io = { workspace = true }
 sp-runtime = { features = ["serde"], workspace = true }
-sp-std = { workspace = true }
 sp-version = { features = ["serde"], workspace = true }
 sp-weights = { features = ["serde"], workspace = true }
 
@@ -47,7 +46,6 @@ std = [
 	"sp-externalities/std",
 	"sp-io/std",
 	"sp-runtime/std",
-	"sp-std/std",
 	"sp-version/std",
 	"sp-weights/std",
 ]
diff --git a/substrate/frame/system/src/lib.rs b/substrate/frame/system/src/lib.rs
index 4fc69c8755f..894e1898ed1 100644
--- a/substrate/frame/system/src/lib.rs
+++ b/substrate/frame/system/src/lib.rs
@@ -120,8 +120,6 @@ use sp_runtime::{
 	},
 	DispatchError, RuntimeDebug,
 };
-#[cfg(any(feature = "std", test))]
-use sp_std::map;
 use sp_version::RuntimeVersion;
 
 use codec::{Decode, Encode, EncodeLike, FullCodec, MaxEncodedLen};
@@ -1920,12 +1918,14 @@ impl<T: Config> Pallet<T> {
 	#[cfg(any(feature = "std", test))]
 	pub fn externalities() -> TestExternalities {
 		TestExternalities::new(sp_core::storage::Storage {
-			top: map![
-				<BlockHash<T>>::hashed_key_for(BlockNumberFor::<T>::zero()) => [69u8; 32].encode(),
-				<Number<T>>::hashed_key().to_vec() => BlockNumberFor::<T>::one().encode(),
-				<ParentHash<T>>::hashed_key().to_vec() => [69u8; 32].encode()
-			],
-			children_default: map![],
+			top: [
+				(<BlockHash<T>>::hashed_key_for(BlockNumberFor::<T>::zero()), [69u8; 32].encode()),
+				(<Number<T>>::hashed_key().to_vec(), BlockNumberFor::<T>::one().encode()),
+				(<ParentHash<T>>::hashed_key().to_vec(), [69u8; 32].encode()),
+			]
+			.into_iter()
+			.collect(),
+			children_default: Default::default(),
 		})
 	}
 
diff --git a/substrate/frame/uniques/Cargo.toml b/substrate/frame/uniques/Cargo.toml
index 135292fb4ec..a2473c51ee7 100644
--- a/substrate/frame/uniques/Cargo.toml
+++ b/substrate/frame/uniques/Cargo.toml
@@ -28,7 +28,6 @@ sp-runtime = { workspace = true }
 pallet-balances = { workspace = true, default-features = true }
 sp-core = { workspace = true, default-features = true }
 sp-io = { workspace = true, default-features = true }
-sp-std = { workspace = true, default-features = true }
 
 [features]
 default = ["std"]
diff --git a/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs b/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs
index d8510a60a78..6b8471f8484 100644
--- a/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs
+++ b/substrate/primitives/runtime/src/generic/unchecked_extrinsic.rs
@@ -683,7 +683,7 @@ mod legacy {
 		Extra: Encode,
 	{
 		fn encode(&self) -> Vec<u8> {
-			let mut tmp = Vec::with_capacity(sp_std::mem::size_of::<Self>());
+			let mut tmp = Vec::with_capacity(core::mem::size_of::<Self>());
 
 			// 1 byte version id.
 			match self.signature.as_ref() {
diff --git a/substrate/primitives/runtime/src/proving_trie/base16.rs b/substrate/primitives/runtime/src/proving_trie/base16.rs
index da05c551c6d..abdf6ed178b 100644
--- a/substrate/primitives/runtime/src/proving_trie/base16.rs
+++ b/substrate/primitives/runtime/src/proving_trie/base16.rs
@@ -26,8 +26,8 @@
 
 use super::{ProofToHashes, ProvingTrie, TrieError};
 use crate::{Decode, DispatchError, Encode};
+use alloc::vec::Vec;
 use codec::MaxEncodedLen;
-use sp_std::vec::Vec;
 use sp_trie::{
 	trie_types::{TrieDBBuilder, TrieDBMutBuilderV1},
 	LayoutV1, MemoryDB, Trie, TrieMut,
@@ -197,7 +197,7 @@ mod tests {
 	use super::*;
 	use crate::traits::BlakeTwo256;
 	use sp_core::H256;
-	use sp_std::collections::btree_map::BTreeMap;
+	use std::collections::BTreeMap;
 
 	// A trie which simulates a trie of accounts (u32) and balances (u128).
 	type BalanceTrie = BasicProvingTrie<BlakeTwo256, u32, u128>;
diff --git a/substrate/primitives/runtime/src/proving_trie/base2.rs b/substrate/primitives/runtime/src/proving_trie/base2.rs
index 2b14a59ab05..8a7cfaa5149 100644
--- a/substrate/primitives/runtime/src/proving_trie/base2.rs
+++ b/substrate/primitives/runtime/src/proving_trie/base2.rs
@@ -22,9 +22,9 @@
 
 use super::{ProofToHashes, ProvingTrie, TrieError};
 use crate::{Decode, DispatchError, Encode};
+use alloc::{collections::BTreeMap, vec::Vec};
 use binary_merkle_tree::{merkle_proof, merkle_root, MerkleProof};
 use codec::MaxEncodedLen;
-use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
 
 /// A helper structure for building a basic base-2 merkle trie and creating compact proofs for that
 /// trie.
@@ -161,7 +161,7 @@ mod tests {
 	use super::*;
 	use crate::traits::BlakeTwo256;
 	use sp_core::H256;
-	use sp_std::collections::btree_map::BTreeMap;
+	use std::collections::BTreeMap;
 
 	// A trie which simulates a trie of accounts (u32) and balances (u128).
 	type BalanceTrie = BasicProvingTrie<BlakeTwo256, u32, u128>;
diff --git a/substrate/primitives/runtime/src/proving_trie/mod.rs b/substrate/primitives/runtime/src/proving_trie/mod.rs
index 009aa6d4935..32b2284b4d7 100644
--- a/substrate/primitives/runtime/src/proving_trie/mod.rs
+++ b/substrate/primitives/runtime/src/proving_trie/mod.rs
@@ -23,7 +23,7 @@ pub mod base2;
 use crate::{Decode, DispatchError, Encode, MaxEncodedLen, TypeInfo};
 #[cfg(feature = "serde")]
 use crate::{Deserialize, Serialize};
-use sp_std::vec::Vec;
+use alloc::vec::Vec;
 use sp_trie::{trie_types::TrieError as SpTrieError, VerifyError};
 
 /// A runtime friendly error type for tries.
diff --git a/substrate/primitives/runtime/src/runtime_logger.rs b/substrate/primitives/runtime/src/runtime_logger.rs
index 79984b13567..ec5251d978f 100644
--- a/substrate/primitives/runtime/src/runtime_logger.rs
+++ b/substrate/primitives/runtime/src/runtime_logger.rs
@@ -54,10 +54,10 @@ impl log::Log for RuntimeLogger {
 
 	fn log(&self, record: &log::Record) {
 		use core::fmt::Write;
-		let mut w = sp_std::Writer::default();
-		let _ = ::core::write!(&mut w, "{}", record.args());
+		let mut msg = alloc::string::String::default();
+		let _ = ::core::write!(&mut msg, "{}", record.args());
 
-		sp_io::logging::log(record.level().into(), record.target(), w.inner());
+		sp_io::logging::log(record.level().into(), record.target(), msg.as_bytes());
 	}
 
 	fn flush(&self) {}
diff --git a/substrate/primitives/runtime/src/traits/mod.rs b/substrate/primitives/runtime/src/traits/mod.rs
index d371152dc40..5b6cacc7e00 100644
--- a/substrate/primitives/runtime/src/traits/mod.rs
+++ b/substrate/primitives/runtime/src/traits/mod.rs
@@ -1710,7 +1710,7 @@ pub trait SignedExtension:
 	/// This method provides a default implementation that returns a vec containing a single
 	/// [`TransactionExtensionMetadata`].
 	fn metadata() -> Vec<TransactionExtensionMetadata> {
-		sp_std::vec![TransactionExtensionMetadata {
+		alloc::vec![TransactionExtensionMetadata {
 			identifier: Self::IDENTIFIER,
 			ty: scale_info::meta_type::<Self>(),
 			implicit: scale_info::meta_type::<Self::AdditionalSigned>()
diff --git a/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs b/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs
index 4d95e5e6f3a..15be1e4c8e0 100644
--- a/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs
+++ b/substrate/primitives/runtime/src/traits/transaction_extension/mod.rs
@@ -24,11 +24,12 @@ use crate::{
 	},
 	DispatchResult,
 };
+use alloc::vec::Vec;
 use codec::{Codec, Decode, Encode};
-use impl_trait_for_tuples::impl_for_tuples;
+use core::fmt::Debug;
 #[doc(hidden)]
-pub use sp_std::marker::PhantomData;
-use sp_std::{self, fmt::Debug, prelude::*};
+pub use core::marker::PhantomData;
+use impl_trait_for_tuples::impl_for_tuples;
 use sp_weights::Weight;
 use tuplex::{PopFront, PushBack};
 
@@ -258,7 +259,7 @@ pub trait TransactionExtension<Call: Dispatchable>:
 	/// This method provides a default implementation that returns a vec containing a single
 	/// [`TransactionExtensionMetadata`].
 	fn metadata() -> Vec<TransactionExtensionMetadata> {
-		sp_std::vec![TransactionExtensionMetadata {
+		alloc::vec![TransactionExtensionMetadata {
 			identifier: Self::IDENTIFIER,
 			ty: scale_info::meta_type::<Self>(),
 			implicit: scale_info::meta_type::<Self::Implicit>()
@@ -668,7 +669,7 @@ impl<Call: Dispatchable> TransactionExtension<Call> for Tuple {
 impl<Call: Dispatchable> TransactionExtension<Call> for () {
 	const IDENTIFIER: &'static str = "UnitTransactionExtension";
 	type Implicit = ();
-	fn implicit(&self) -> sp_std::result::Result<Self::Implicit, TransactionValidityError> {
+	fn implicit(&self) -> core::result::Result<Self::Implicit, TransactionValidityError> {
 		Ok(())
 	}
 	type Val = ();
-- 
GitLab