diff --git a/substrate/wasm-runtime/polkadot/src/codec/endiansensitive.rs b/substrate/wasm-runtime/polkadot/src/codec/endiansensitive.rs index a1576284228e952e51be44b55af5f8b48dfbf845..c4978d5ce4721685bb81e932177825e6ca033b96 100644 --- a/substrate/wasm-runtime/polkadot/src/codec/endiansensitive.rs +++ b/substrate/wasm-runtime/polkadot/src/codec/endiansensitive.rs @@ -17,7 +17,8 @@ //! Endian manager. /// Trait to allow conversion to a know endian representation when sensitive. -pub trait EndianSensitive: Sized { +// note: the copy bound and static lifetimes are necessary for safety of `Slicable` blanket implementation. +pub trait EndianSensitive: Copy + 'static { fn to_le(self) -> Self { self } fn to_be(self) -> Self { self } fn from_le(self) -> Self { self } @@ -48,3 +49,20 @@ impl_endians!(u16, u32, u64, usize, i16, i32, i64, isize); impl_non_endians!(u8, i8, [u8; 1], [u8; 2], [u8; 3], [u8; 4], [u8; 5], [u8; 6], [u8; 7], [u8; 8], [u8; 10], [u8; 12], [u8; 14], [u8; 16], [u8; 20], [u8; 24], [u8; 28], [u8; 32], [u8; 40], [u8; 48], [u8; 56], [u8; 64], [u8; 80], [u8; 96], [u8; 112], [u8; 128]); + +#[cfg(test)] +mod tests { + use super::EndianSensitive; + + #[test] + fn endian_sensitive_is_copy() { + fn _takes_copy<T: Copy>() { } + fn _takes_endian_sensitive<T: EndianSensitive>() { _takes_copy::<T>() } + } + + #[test] + fn endian_sensitive_outlives_static() { + fn _takes_static<T: 'static>() { } + fn _takes_endian_sensitive<T: EndianSensitive>() { _takes_static::<T>() } + } +} diff --git a/substrate/wasm-runtime/polkadot/src/codec/joiner.rs b/substrate/wasm-runtime/polkadot/src/codec/joiner.rs index db38cacbd95ccb6ef6e891c30db1333df3006101..7fdb1e16456c61d4865894ac391110186aba81ea 100644 --- a/substrate/wasm-runtime/polkadot/src/codec/joiner.rs +++ b/substrate/wasm-runtime/polkadot/src/codec/joiner.rs @@ -16,7 +16,7 @@ //! Vec<u8> serialiser. -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use slicable::Slicable; /// Trait to allow itself to be serialised into a `Vec<u8>` diff --git a/substrate/wasm-runtime/polkadot/src/codec/keyedvec.rs b/substrate/wasm-runtime/polkadot/src/codec/keyedvec.rs index b1f903643c1d7543239271598ae9d54b190dfe56..210606ab7c92331de901497f524ef821891a8844 100644 --- a/substrate/wasm-runtime/polkadot/src/codec/keyedvec.rs +++ b/substrate/wasm-runtime/polkadot/src/codec/keyedvec.rs @@ -16,7 +16,7 @@ //! Serialiser and prepender. -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use slicable::Slicable; /// Trait to allow itselg to be serialised and prepended by a given slice. diff --git a/substrate/wasm-runtime/polkadot/src/codec/slicable.rs b/substrate/wasm-runtime/polkadot/src/codec/slicable.rs index 2dfc2db49fd61207c70c9c459dca52f66920d66b..40f8a532b7131e0c001a4c5ad83dfbc40327d3c1 100644 --- a/substrate/wasm-runtime/polkadot/src/codec/slicable.rs +++ b/substrate/wasm-runtime/polkadot/src/codec/slicable.rs @@ -16,7 +16,7 @@ //! Serialisation. -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use runtime_support::{mem, slice}; use joiner::Joiner; use endiansensitive::EndianSensitive; @@ -44,8 +44,7 @@ pub trait Slicable: Sized { /// Trait to mark that a type is not trivially (essentially "in place") serialisable. pub trait NonTrivialSlicable: Slicable {} -// note: the copy bound and static lifetimes are necessary for safety of `set_as_slice`. -impl<T: Copy + EndianSensitive + 'static> Slicable for T { +impl<T: EndianSensitive> Slicable for T { fn set_as_slice<F: FnOnce(&mut [u8]) -> bool>(fill_slice: F) -> Option<Self> { let size = mem::size_of::<T>(); let mut result: T = unsafe { mem::zeroed() }; diff --git a/substrate/wasm-runtime/polkadot/src/runtime/consensus.rs b/substrate/wasm-runtime/polkadot/src/runtime/consensus.rs index 1b897a86cab083308b2c33c492ef361d215e3094..689fdca21e682a81c797ba43f2e966206ce47970 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/consensus.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/consensus.rs @@ -16,7 +16,7 @@ //! Conensus module for runtime; manages the authority set ready for the native code. -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use storable::StorageVec; use primitives::SessionKey; diff --git a/substrate/wasm-runtime/polkadot/src/runtime/session.rs b/substrate/wasm-runtime/polkadot/src/runtime/session.rs index 34c67c9811c751347144538c115b7a4fb67f2113..6914bdc6558834d55682b3860f556c53102fcf42 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/session.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/session.rs @@ -17,7 +17,7 @@ //! Session manager: is told the validators and allows them to manage their session keys for the //! consensus module. -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use keyedvec::KeyedVec; use storable::{kill, Storable, StorageVec}; use primitives::{AccountID, SessionKey, BlockNumber}; diff --git a/substrate/wasm-runtime/polkadot/src/runtime/staking.rs b/substrate/wasm-runtime/polkadot/src/runtime/staking.rs index 5f39ec14b26128757e4d10a9c03a877939c4e382..9b0c659f5c9abd9b6c17858d2981a6e554d09159 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/staking.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/staking.rs @@ -16,7 +16,7 @@ //! Staking manager: Handles balances and periodically determines the best set of validators. -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use keyedvec::KeyedVec; use storable::{Storable, StorageVec}; use primitives::{BlockNumber, AccountID}; diff --git a/substrate/wasm-runtime/polkadot/src/runtime/system.rs b/substrate/wasm-runtime/polkadot/src/runtime/system.rs index f6243ff4f7c15baa951399981d30540025258b6e..072e17df010c9061014039bbeb29232d5de748e7 100644 --- a/substrate/wasm-runtime/polkadot/src/runtime/system.rs +++ b/substrate/wasm-runtime/polkadot/src/runtime/system.rs @@ -19,7 +19,7 @@ use primitives::{Block, BlockNumber, Hash, UncheckedTransaction, TxOrder, Hashable}; use runtime_support::mem; -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use storable::Storable; use keyedvec::KeyedVec; use environment::with_env; diff --git a/substrate/wasm-runtime/polkadot/src/support/primitives.rs b/substrate/wasm-runtime/polkadot/src/support/primitives.rs index ea94c0319051931cbb3bf27798cb4bb91260aff3..338be8071050e7ef14eb64023811c2437bc3ca42 100644 --- a/substrate/wasm-runtime/polkadot/src/support/primitives.rs +++ b/substrate/wasm-runtime/polkadot/src/support/primitives.rs @@ -16,7 +16,7 @@ //! Primitive types. -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use streamreader::StreamReader; use joiner::Joiner; use slicable::{Slicable, NonTrivialSlicable}; diff --git a/substrate/wasm-runtime/polkadot/src/support/storable.rs b/substrate/wasm-runtime/polkadot/src/support/storable.rs index 835e70ff3d51fbb7f9f8018a406850768f8b598a..9a871a638be5cc7c5596c9124175b9b1b7fcbf14 100644 --- a/substrate/wasm-runtime/polkadot/src/support/storable.rs +++ b/substrate/wasm-runtime/polkadot/src/support/storable.rs @@ -19,7 +19,7 @@ use slicable::Slicable; use endiansensitive::EndianSensitive; use keyedvec::KeyedVec; -use runtime_support::vec::Vec; +use runtime_support::prelude::*; use runtime_support::{self, twox_128}; /// Trait for a value which may be stored in the storage DB. @@ -37,7 +37,7 @@ pub trait Storable { /// Remove `key` from storage. pub fn kill(key: &[u8]) { runtime_support::set_storage(&twox_128(key)[..], b""); } -impl<T: Default + Copy + EndianSensitive + 'static> Storable for T { +impl<T: Default + EndianSensitive> Storable for T { fn lookup(key: &[u8]) -> Option<Self> { Slicable::set_as_slice(|out| runtime_support::read_storage(&twox_128(key)[..], out) == out.len()) }