diff --git a/Cargo.lock b/Cargo.lock index 3d7dc3551aa..593e90356f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2274,7 +2274,6 @@ dependencies = [ "parity-scale-codec", "rand 0.8.5", "rand_pcg", - "static_assertions", ] [[package]] @@ -3740,7 +3739,6 @@ dependencies = [ "hex-literal", "log", "parity-scale-codec", - "static_assertions", "subxt", "thiserror", "tokio", @@ -3759,7 +3757,6 @@ dependencies = [ "gsys", "hex-literal", "parity-scale-codec", - "static_assertions", ] [[package]] @@ -3919,7 +3916,6 @@ dependencies = [ "rand 0.8.5", "scale-info", "serde", - "static_assertions", "wabt", "wasmparser-nostd 0.100.1", ] @@ -4180,7 +4176,6 @@ dependencies = [ "sp-runtime-interface", "sp-std 8.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1.0.0-canary)", "sp-wasm-interface", - "static_assertions", "winapi", ] @@ -4396,7 +4391,6 @@ dependencies = [ "log", "proptest", "rand 0.8.5", - "static_assertions", "thiserror", "wasm-smith", "wasmparser-nostd 0.100.1", @@ -4676,7 +4670,6 @@ dependencies = [ "parity-scale-codec", "primitive-types", "scale-info", - "static_assertions", ] [[package]] @@ -7566,7 +7559,6 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std 8.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1.0.0-canary)", - "static_assertions", "test-syscalls", "wabt", ] @@ -7743,7 +7735,6 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std 8.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1.0.0-canary)", - "static_assertions", ] [[package]] @@ -9556,7 +9547,6 @@ dependencies = [ "sp-io", "sp-keyring", "sp-runtime", - "static_assertions", "vara-runtime", ] @@ -13525,7 +13515,6 @@ dependencies = [ "sp-std 8.0.0 (git+https://github.com/gear-tech/substrate.git?branch=gear-polkadot-v1.0.0-canary)", "sp-transaction-pool", "sp-version", - "static_assertions", "substrate-build-script-utils", "substrate-wasm-builder", "wat", diff --git a/Cargo.toml b/Cargo.toml index f51541d9eef..bb888dda646 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,7 +145,6 @@ serde = "^1" serde_json = "^1" serde_yaml = "0.8.26" sha-1 = "0.10.1" -static_assertions = "1" subxt = "0.32.1" subxt-metadata = "0.32.1" subxt-codegen = "0.32.1" diff --git a/core/Cargo.toml b/core/Cargo.toml index 70bf12eb509..98c75a5cd09 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -22,7 +22,6 @@ gear-wasm-instrument.workspace = true wasmparser.workspace = true hex = { workspace = true, features = ["alloc"] } hashbrown.workspace = true -static_assertions.workspace = true paste.workspace = true enum-iterator.workspace = true byteorder.workspace = true diff --git a/core/src/lib.rs b/core/src/lib.rs index cd9b6c45654..b9e0c67664f 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -44,8 +44,5 @@ pub mod reservation; pub mod buffer; pub mod str; -use core::mem::size_of; -use static_assertions::const_assert; - // This allows all casts from u32 into usize be safe. -const_assert!(size_of::() <= size_of::()); +const _: () = assert!(core::mem::size_of::() <= core::mem::size_of::()); diff --git a/core/src/memory.rs b/core/src/memory.rs index a86643128f9..c5981f056af 100644 --- a/core/src/memory.rs +++ b/core/src/memory.rs @@ -175,9 +175,7 @@ impl PageBuf { /// Host pointer can be 64bit or less, to support both we use u64. pub type HostPointer = u64; -static_assertions::const_assert!( - core::mem::size_of::() >= core::mem::size_of::() -); +const _: () = assert!(core::mem::size_of::() >= core::mem::size_of::()); /// Core memory error. #[derive(Debug, Clone, Eq, PartialEq, derive_more::Display)] diff --git a/core/src/message/mod.rs b/core/src/message/mod.rs index 53d0dbd3405..88b37c994f6 100644 --- a/core/src/message/mod.rs +++ b/core/src/message/mod.rs @@ -55,7 +55,7 @@ pub const MAX_PAYLOAD_SIZE: usize = 8 * 1024 * 1024; // **WARNING**: do not remove this check until be sure that // all `MAX_PAYLOAD_SIZE` conversions are safe! -static_assertions::const_assert!(MAX_PAYLOAD_SIZE <= u32::MAX as usize); +const _: () = assert!(MAX_PAYLOAD_SIZE <= u32::MAX as usize); /// Payload size exceed error #[derive( diff --git a/core/src/pages.rs b/core/src/pages.rs index 3e6478018d8..e53ed28d05e 100644 --- a/core/src/pages.rs +++ b/core/src/pages.rs @@ -35,8 +35,8 @@ pub const WASM_PAGE_SIZE: usize = 0x10000; /// native page size, so can vary. pub const GEAR_PAGE_SIZE: usize = 0x4000; -static_assertions::const_assert!(WASM_PAGE_SIZE < u32::MAX as usize); -static_assertions::const_assert_eq!(WASM_PAGE_SIZE % GEAR_PAGE_SIZE, 0); +const _: () = assert!(WASM_PAGE_SIZE < u32::MAX as usize); +const _: () = assert!(WASM_PAGE_SIZE % GEAR_PAGE_SIZE == 0); /// Errors when act with PageU32Size. #[derive(Debug, Clone, derive_more::Display)] @@ -64,7 +64,7 @@ pub struct GearPage(pub(crate) u32); impl From for GearPage { fn from(value: u16) -> Self { // u16::MAX * GearPage::size() - 1 <= u32::MAX - static_assertions::const_assert!(GEAR_PAGE_SIZE <= 0x10000); + const _: () = assert!(GEAR_PAGE_SIZE <= 0x10000); GearPage(value as u32) } } @@ -77,7 +77,7 @@ impl From for u32 { impl PageU32Size for GearPage { fn size_non_zero() -> NonZeroU32 { - static_assertions::const_assert_ne!(GEAR_PAGE_SIZE, 0); + const _: () = assert!(GEAR_PAGE_SIZE != 0); unsafe { NonZeroU32::new_unchecked(GEAR_PAGE_SIZE as u32) } } @@ -102,7 +102,7 @@ pub struct WasmPage(pub(crate) u32); impl From for WasmPage { fn from(value: u16) -> Self { // u16::MAX * WasmPage::size() - 1 == u32::MAX - static_assertions::const_assert!(WASM_PAGE_SIZE == 0x10000); + const _: () = assert!(WASM_PAGE_SIZE == 0x10000); WasmPage(value as u32) } } @@ -121,7 +121,7 @@ impl PageNumber for WasmPage { impl PageU32Size for WasmPage { fn size_non_zero() -> NonZeroU32 { - static_assertions::const_assert_ne!(WASM_PAGE_SIZE, 0); + const _: () = assert!(WASM_PAGE_SIZE != 0); unsafe { NonZeroU32::new_unchecked(WASM_PAGE_SIZE as u32) } } diff --git a/examples/stack-allocations/Cargo.toml b/examples/stack-allocations/Cargo.toml index e6b8fe0c32e..53bc2070b90 100644 --- a/examples/stack-allocations/Cargo.toml +++ b/examples/stack-allocations/Cargo.toml @@ -15,7 +15,6 @@ parity-scale-codec.workspace = true gtest.workspace = true rand_pcg.workspace = true rand.workspace = true -static_assertions.workspace = true [build-dependencies] gear-wasm-builder.workspace = true diff --git a/examples/stack-allocations/src/lib.rs b/examples/stack-allocations/src/lib.rs index 5aa80e5d0aa..64333907992 100644 --- a/examples/stack-allocations/src/lib.rs +++ b/examples/stack-allocations/src/lib.rs @@ -67,7 +67,6 @@ mod tests { use gtest::{Program, System}; use parity_scale_codec::Decode; use rand::{Rng, SeedableRng}; - use static_assertions::const_assert; #[test] fn stress() { @@ -77,11 +76,11 @@ mod tests { const MAX_NUMBER: u8 = 255; // Check that check sum is less than u32::MAX - const_assert!( + const _: () = assert!( MAX_ACTIONS_AMOUNT * MAX_NUMBER as usize * HANDLE_DATA_SIZE <= u32::MAX as usize ); // Check that we can fit all the data in the stack (heuristic no more than 10 wasm pages) - const_assert!(MAX_ACTIONS_AMOUNT * HANDLE_DATA_SIZE <= 64 * 1024 * 10); + const _: () = assert!(MAX_ACTIONS_AMOUNT * HANDLE_DATA_SIZE <= 64 * 1024 * 10); let from = 42; let system = System::new(); diff --git a/gclient/Cargo.toml b/gclient/Cargo.toml index e869aeb4e5c..daf873f476c 100644 --- a/gclient/Cargo.toml +++ b/gclient/Cargo.toml @@ -23,7 +23,6 @@ thiserror.workspace = true async-trait.workspace = true url.workspace = true wabt.workspace = true -static_assertions.workspace = true [dev-dependencies] tokio = { workspace = true, features = ["full"] } diff --git a/gclient/src/api/calls.rs b/gclient/src/api/calls.rs index 4c70f5f46d1..fa946c25455 100644 --- a/gclient/src/api/calls.rs +++ b/gclient/src/api/calls.rs @@ -532,7 +532,7 @@ impl GearApi { ) -> Result { let program = self.0.api().gprog_at(program_id, block_hash).await?; - static_assertions::const_assert_eq!(WASM_PAGE_SIZE % GEAR_PAGE_SIZE, 0); + const _: () = assert!(WASM_PAGE_SIZE % GEAR_PAGE_SIZE == 0); assert!(program.static_pages.0 > 0); let static_page_count = (program.static_pages.0 as usize - 1) * WASM_PAGE_SIZE / GEAR_PAGE_SIZE; diff --git a/gcore/Cargo.toml b/gcore/Cargo.toml index f0e4ac0fdea..31af69700f3 100644 --- a/gcore/Cargo.toml +++ b/gcore/Cargo.toml @@ -11,7 +11,6 @@ gsys.workspace = true gear-core-errors.workspace = true gear-stack-buffer.workspace = true codec = { workspace = true, optional = true } -static_assertions.workspace = true [dev-dependencies] hex-literal.workspace = true diff --git a/gcore/src/lib.rs b/gcore/src/lib.rs index bcc7ce64e02..aaf1705b7c0 100644 --- a/gcore/src/lib.rs +++ b/gcore/src/lib.rs @@ -83,8 +83,5 @@ pub use utils::ext; pub use gsys::{BlockCount, BlockNumber, Gas, GasMultiplier, Percent, Value}; -use core::mem::size_of; -use static_assertions::const_assert; - // This allows all casts from u32 into usize be safe. -const_assert!(size_of::() <= size_of::()); +const _: () = assert!(core::mem::size_of::() <= core::mem::size_of::()); diff --git a/gstd/Cargo.toml b/gstd/Cargo.toml index 3b9ae7a9f78..9eef9a5c005 100644 --- a/gstd/Cargo.toml +++ b/gstd/Cargo.toml @@ -24,8 +24,6 @@ primitive-types = { workspace = true, features = ["scale-info"] } scale-info = { workspace = true, features = ["derive"] } futures = { workspace = true, features = ["alloc"] } -static_assertions.workspace = true - [features] #! ## Default features diff --git a/gstd/src/lib.rs b/gstd/src/lib.rs index 6749a219a01..7a60e321812 100644 --- a/gstd/src/lib.rs +++ b/gstd/src/lib.rs @@ -166,8 +166,5 @@ pub use gstd_codegen::{async_init, async_main}; pub use prelude::*; pub use reservations::*; -use core::mem::size_of; -use static_assertions::const_assert; - // This allows all casts from u32 into usize be safe. -const_assert!(size_of::() <= size_of::()); +const _: () = assert!(core::mem::size_of::() <= core::mem::size_of::()); diff --git a/pallets/gear-program/Cargo.toml b/pallets/gear-program/Cargo.toml index 7b1a063b145..b6e51e49e9e 100644 --- a/pallets/gear-program/Cargo.toml +++ b/pallets/gear-program/Cargo.toml @@ -18,7 +18,6 @@ scale-info = { workspace = true, features = ["derive"] } primitive-types = { workspace = true, features = ["scale-info"] } log.workspace = true hashbrown.workspace = true -static_assertions.workspace = true # Internal deps common.workspace = true diff --git a/pallets/gear/Cargo.toml b/pallets/gear/Cargo.toml index 6d3d8806fed..f449814e4a4 100644 --- a/pallets/gear/Cargo.toml +++ b/pallets/gear/Cargo.toml @@ -21,7 +21,6 @@ gear-wasm-instrument.workspace = true derive_more.workspace = true env_logger = { workspace = true, optional = true } scopeguard.workspace = true -static_assertions.workspace = true # Internal deps common.workspace = true diff --git a/pallets/gear/src/schedule.rs b/pallets/gear/src/schedule.rs index 8e66299e561..ab1c1662a97 100644 --- a/pallets/gear/src/schedule.rs +++ b/pallets/gear/src/schedule.rs @@ -1070,8 +1070,8 @@ impl Default for MemoryWeights { } const KB_AMOUNT_IN_ONE_GEAR_PAGE: u64 = GEAR_PAGE_SIZE as u64 / KB_SIZE; - static_assertions::const_assert!(KB_AMOUNT_IN_ONE_GEAR_PAGE > 0); - static_assertions::const_assert!(GEAR_PAGE_SIZE as u64 % KB_SIZE == 0); + const _: () = assert!(KB_AMOUNT_IN_ONE_GEAR_PAGE > 0); + const _: () = assert!(GEAR_PAGE_SIZE as u64 % KB_SIZE == 0); Self { lazy_pages_signal_read: to_weight!(to_cost_per_gear_page!(lazy_pages_signal_read)), diff --git a/runtime-interface/Cargo.toml b/runtime-interface/Cargo.toml index aa29864c041..20ebcae809c 100644 --- a/runtime-interface/Cargo.toml +++ b/runtime-interface/Cargo.toml @@ -22,8 +22,6 @@ sp-wasm-interface.workspace = true byteorder.workspace = true codec = { workspace = true } log = { workspace = true, optional = true } -static_assertions.workspace = true - [target.'cfg(windows)'.dependencies] winapi = { workspace = true, features = ["memoryapi"] } diff --git a/runtime-interface/src/lib.rs b/runtime-interface/src/lib.rs index 9ac73217680..3bf07f82d8e 100644 --- a/runtime-interface/src/lib.rs +++ b/runtime-interface/src/lib.rs @@ -45,9 +45,7 @@ mod gear_sandbox; pub use gear_sandbox::init as sandbox_init; pub use gear_sandbox::sandbox; -static_assertions::const_assert!( - core::mem::size_of::() >= core::mem::size_of::() -); +const _: () = assert!(core::mem::size_of::() >= core::mem::size_of::()); #[derive(Debug, Clone, Encode, Decode)] #[codec(crate = codec)] diff --git a/runtime/vara/Cargo.toml b/runtime/vara/Cargo.toml index 1c5d1b19d73..354640ebaac 100644 --- a/runtime/vara/Cargo.toml +++ b/runtime/vara/Cargo.toml @@ -16,7 +16,6 @@ const-str.workspace = true log.workspace = true parity-scale-codec.workspace = true scale-info = { workspace = true, features = ["derive"] } -static_assertions.workspace = true # Frame deps frame-support.workspace = true diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index 65001542699..051befb1eab 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -99,7 +99,6 @@ use sp_std::{ #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use static_assertions::const_assert; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -174,8 +173,8 @@ pub const BABE_GENESIS_EPOCH_CONFIG: sp_consensus_babe::BabeEpochConfiguration = // We'll verify that WEIGHT_REF_TIME_PER_SECOND does not overflow, allowing us to use // simple multiply and divide operators instead of saturating or checked ones. -const_assert!(WEIGHT_REF_TIME_PER_SECOND.checked_div(3).is_some()); -const_assert!((WEIGHT_REF_TIME_PER_SECOND / 3).checked_mul(2).is_some()); +const _: () = assert!(WEIGHT_REF_TIME_PER_SECOND.checked_div(3).is_some()); +const _: () = assert!((WEIGHT_REF_TIME_PER_SECOND / 3).checked_mul(2).is_some()); /// We allow for 1/3 of block time for computations, with maximum proof size. /// diff --git a/scripts/src/clippy.sh b/scripts/src/clippy.sh index 0133a609d66..5a381a2c3c8 100755 --- a/scripts/src/clippy.sh +++ b/scripts/src/clippy.sh @@ -20,14 +20,14 @@ EOF } gear_clippy() { - # TODO #3452: remove `-A clippy::needless_pass_by_ref_mut` on next rust update + # TODO #3452: remove `-A clippy::needless_pass_by_ref_mut`, `-A clippy::assertions_on_constants` on next rust update EXCLUDE_PACKAGES="--exclude vara-runtime --exclude runtime-fuzzer --exclude runtime-fuzzer-fuzz" INCLUDE_PACKAGES="-p vara-runtime -p runtime-fuzzer -p runtime-fuzzer-fuzz" - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy --workspace "$@" $EXCLUDE_PACKAGES -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy $INCLUDE_PACKAGES --all-features -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy --workspace "$@" $EXCLUDE_PACKAGES -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut -A clippy::assertions_on_constants + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy $INCLUDE_PACKAGES --all-features -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut -A clippy::assertions_on_constants } examples_clippy() { - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut -A clippy::assertions_on_constants } diff --git a/utils/runtime-fuzzer/Cargo.toml b/utils/runtime-fuzzer/Cargo.toml index ff5195265ae..e950e495106 100644 --- a/utils/runtime-fuzzer/Cargo.toml +++ b/utils/runtime-fuzzer/Cargo.toml @@ -15,7 +15,6 @@ codec = { workspace = true, features = ["derive"] } hex.workspace = true log.workspace = true sha-1.workspace = true -static_assertions.workspace = true # Temporary deps for the reproducing crash script until #2313 is implemented clap = { workspace = true, features = ["derive"] } diff --git a/utils/runtime-fuzzer/src/gear_calls.rs b/utils/runtime-fuzzer/src/gear_calls.rs index 985c1b2e287..cc7777f3bd3 100644 --- a/utils/runtime-fuzzer/src/gear_calls.rs +++ b/utils/runtime-fuzzer/src/gear_calls.rs @@ -44,7 +44,7 @@ use std::mem; /// /// TODO: #3442 const MAX_PAYLOAD_SIZE: usize = 1024; -static_assertions::const_assert!(MAX_PAYLOAD_SIZE <= gear_core::message::MAX_PAYLOAD_SIZE); +const _: () = assert!(MAX_PAYLOAD_SIZE <= gear_core::message::MAX_PAYLOAD_SIZE); /// Maximum salt size for the fuzzer - 512 bytes. /// @@ -52,7 +52,7 @@ static_assertions::const_assert!(MAX_PAYLOAD_SIZE <= gear_core::message::MAX_PAY /// for one run. Also small salt will make overall size of the /// corpus smaller. const MAX_SALT_SIZE: usize = 512; -static_assertions::const_assert!(MAX_SALT_SIZE <= gear_core::message::MAX_PAYLOAD_SIZE); +const _: () = assert!(MAX_SALT_SIZE <= gear_core::message::MAX_PAYLOAD_SIZE); const ID_SIZE: usize = mem::size_of::(); const GAS_AND_VALUE_SIZE: usize = mem::size_of::<(u64, u128)>(); diff --git a/utils/wasm-gen/Cargo.toml b/utils/wasm-gen/Cargo.toml index c732b30a91b..2209d12c8ed 100644 --- a/utils/wasm-gen/Cargo.toml +++ b/utils/wasm-gen/Cargo.toml @@ -15,7 +15,6 @@ gsys.workspace = true gear-utils.workspace = true gear-core.workspace = true wasmparser.workspace = true -static_assertions.workspace = true thiserror.workspace = true [dev-dependencies] diff --git a/utils/wasm-gen/src/generator/syscalls/invocator.rs b/utils/wasm-gen/src/generator/syscalls/invocator.rs index c90a6a94e10..c31b117a08e 100644 --- a/utils/wasm-gen/src/generator/syscalls/invocator.rs +++ b/utils/wasm-gen/src/generator/syscalls/invocator.rs @@ -604,7 +604,7 @@ impl<'a, 'b> SyscallsInvocator<'a, 'b> { fallible_signature: FallibleSyscallSignature, param_instructions: Vec, ) -> Vec { - static_assertions::assert_eq_size!(gsys::ErrorCode, u32); + const _: () = assert!(mem::size_of::() == mem::size_of::()); let no_error_val = gsys::ErrorCode::default() as i32; assert_eq!(