From 12189978a16a413dad65120f38346013424eff1a Mon Sep 17 00:00:00 2001 From: Qinxuan Chen Date: Mon, 20 May 2024 15:46:43 +0800 Subject: [PATCH] Use `Display` impl instead of deprecated `description` method of `Error` trait (#286) * Use Display impl instead of deprecated description method of Error trait * make Display impl works in no_std env --- interpreter/src/error.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/interpreter/src/error.rs b/interpreter/src/error.rs index aaf74fbcb..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)] @@ -54,23 +55,18 @@ impl From for ExitResult { } #[cfg(feature = "std")] -impl std::error::Error for ExitError { - fn description(&self) -> &str { +impl std::error::Error for ExitError {} + +impl fmt::Display for ExitError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::Exception(_) => "EVM exit exception", - Self::Reverted => "EVM internal revert", - Self::Fatal(_) => "EVM fatal error", + Self::Exception(_) => f.write_str("EVM exit exception"), + Self::Reverted => f.write_str("EVM internal revert"), + Self::Fatal(_) => f.write_str("EVM fatal error"), } } } -#[cfg(feature = "std")] -impl std::fmt::Display for ExitError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{self:?}") - } -} - /// Exit succeed reason. #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[cfg_attr(