diff --git a/crates/revm/src/db/emptydb.rs b/crates/revm/src/db/emptydb.rs index 3bf50dfb16..eeaaaf928d 100644 --- a/crates/revm/src/db/emptydb.rs +++ b/crates/revm/src/db/emptydb.rs @@ -1,4 +1,4 @@ -use core::{convert::Infallible, marker::PhantomData}; +use core::{convert::Infallible, fmt, marker::PhantomData}; use revm_interpreter::primitives::{ db::{Database, DatabaseRef}, AccountInfo, Bytecode, B160, B256, U256, @@ -10,21 +10,40 @@ pub type EmptyDB = EmptyDBTyped; /// An empty database that always returns default values when queried. /// /// This is generic over a type which is used as the database error type. -#[derive(Debug, Clone)] pub struct EmptyDBTyped { _phantom: PhantomData, } -// Don't derive it because it doesn't need `E: Default`. +// Don't derive traits, because the type parameter is unused. +impl Clone for EmptyDBTyped { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for EmptyDBTyped {} + impl Default for EmptyDBTyped { - #[inline(always)] fn default() -> Self { Self::new() } } +impl fmt::Debug for EmptyDBTyped { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("EmptyDB").finish_non_exhaustive() + } +} + +impl PartialEq for EmptyDBTyped { + fn eq(&self, _: &Self) -> bool { + true + } +} + +impl Eq for EmptyDBTyped {} + impl EmptyDBTyped { - #[inline(always)] pub fn new() -> Self { Self { _phantom: PhantomData, @@ -33,7 +52,6 @@ impl EmptyDBTyped { #[doc(hidden)] #[deprecated = "use `new` instead"] - #[inline(always)] pub fn new_keccak_block_hash() -> Self { Self::new() } @@ -42,22 +60,22 @@ impl EmptyDBTyped { impl Database for EmptyDBTyped { type Error = E; - #[inline(always)] + #[inline] fn basic(&mut self, address: B160) -> Result, Self::Error> { ::basic(self, address) } - #[inline(always)] + #[inline] fn code_by_hash(&mut self, code_hash: B256) -> Result { ::code_by_hash(self, code_hash) } - #[inline(always)] + #[inline] fn storage(&mut self, address: B160, index: U256) -> Result { ::storage(self, address, index) } - #[inline(always)] + #[inline] fn block_hash(&mut self, number: U256) -> Result { ::block_hash(self, number) } @@ -66,22 +84,22 @@ impl Database for EmptyDBTyped { impl DatabaseRef for EmptyDBTyped { type Error = E; - #[inline(always)] + #[inline] fn basic(&self, _address: B160) -> Result, Self::Error> { Ok(None) } - #[inline(always)] + #[inline] fn code_by_hash(&self, _code_hash: B256) -> Result { Ok(Bytecode::new()) } - #[inline(always)] + #[inline] fn storage(&self, _address: B160, _index: U256) -> Result { Ok(U256::default()) } - #[inline(always)] + #[inline] fn block_hash(&self, number: U256) -> Result { Ok(number.to_be_bytes().into()) }