From c82a233aac1a230d7b83c6590930dc51d2de2036 Mon Sep 17 00:00:00 2001 From: koushiro Date: Mon, 20 May 2024 15:40:01 +0800 Subject: [PATCH 1/2] Use Display impl instead of description method of Error trait --- interpreter/src/error.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/interpreter/src/error.rs b/interpreter/src/error.rs index aaf74fbcb..009dde9de 100644 --- a/interpreter/src/error.rs +++ b/interpreter/src/error.rs @@ -54,20 +54,16 @@ impl From for ExitResult { } #[cfg(feature = "std")] -impl std::error::Error for ExitError { - fn description(&self) -> &str { - match self { - Self::Exception(_) => "EVM exit exception", - Self::Reverted => "EVM internal revert", - Self::Fatal(_) => "EVM fatal error", - } - } -} +impl std::error::Error for ExitError {} #[cfg(feature = "std")] impl std::fmt::Display for ExitError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self:?}") + match self { + Self::Exception(_) => f.write_str("EVM exit exception"), + Self::Reverted => f.write_str("EVM internal revert"), + Self::Fatal(_) => f.write_str("EVM fatal error"), + } } } From 1abac11fad447d762270b336c98bb7b9abf1926b Mon Sep 17 00:00:00 2001 From: koushiro Date: Mon, 20 May 2024 15:42:04 +0800 Subject: [PATCH 2/2] make Display impl works in no_std env --- interpreter/src/error.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interpreter/src/error.rs b/interpreter/src/error.rs index 009dde9de..92ead5d0b 100644 --- a/interpreter/src/error.rs +++ b/interpreter/src/error.rs @@ -1,5 +1,6 @@ use crate::Opcode; use alloc::borrow::Cow; +use core::fmt; /// Capture represents the result of execution. #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -56,9 +57,8 @@ impl From for ExitResult { #[cfg(feature = "std")] impl std::error::Error for ExitError {} -#[cfg(feature = "std")] -impl std::fmt::Display for ExitError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for ExitError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::Exception(_) => f.write_str("EVM exit exception"), Self::Reverted => f.write_str("EVM internal revert"),