From f3da7cfacb9964a03e3ee0bc4f2799d564ec1ece Mon Sep 17 00:00:00 2001 From: evalir Date: Wed, 23 Oct 2024 17:28:29 +0200 Subject: [PATCH] chore: use `core::error::Error` --- crates/dyn-abi/src/coerce.rs | 3 +-- crates/primitives/src/postgres.rs | 4 ++-- crates/primitives/src/signed/errors.rs | 3 +-- crates/sol-type-parser/src/error.rs | 3 +-- crates/sol-type-parser/src/input.rs | 3 +-- crates/sol-types/src/types/error.rs | 6 ++---- crates/sol-types/src/types/interface/mod.rs | 8 ++------ crates/syn-solidity/tests/contracts.rs | 2 +- 8 files changed, 11 insertions(+), 21 deletions(-) diff --git a/crates/dyn-abi/src/coerce.rs b/crates/dyn-abi/src/coerce.rs index 0d23acc5f..4f9bd781c 100644 --- a/crates/dyn-abi/src/coerce.rs +++ b/crates/dyn-abi/src/coerce.rs @@ -256,8 +256,7 @@ enum Error { EmptyHexStringWithoutPrefix, } -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/primitives/src/postgres.rs b/crates/primitives/src/postgres.rs index 05fc29f50..ba1c9f25a 100644 --- a/crates/primitives/src/postgres.rs +++ b/crates/primitives/src/postgres.rs @@ -63,7 +63,7 @@ pub enum ToSqlError { Overflow(usize, Type), } -impl std::error::Error for ToSqlError {} +impl core::error::Error for ToSqlError {} /// Convert to Postgres types. /// @@ -225,7 +225,7 @@ pub enum FromSqlError { ParseError(Type), } -impl std::error::Error for FromSqlError {} +impl core::error::Error for FromSqlError {} impl<'a, const BITS: usize, const LIMBS: usize> FromSql<'a> for Signed { fn accepts(ty: &Type) -> bool { diff --git a/crates/primitives/src/signed/errors.rs b/crates/primitives/src/signed/errors.rs index b41c7c80c..72a303f7b 100644 --- a/crates/primitives/src/signed/errors.rs +++ b/crates/primitives/src/signed/errors.rs @@ -48,8 +48,7 @@ impl fmt::Display for ParseSignedError { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct BigIntConversionError; -#[cfg(feature = "std")] -impl std::error::Error for BigIntConversionError {} +impl core::error::Error for BigIntConversionError {} impl fmt::Display for BigIntConversionError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/sol-type-parser/src/error.rs b/crates/sol-type-parser/src/error.rs index 3812fd0b9..2bd87c9d1 100644 --- a/crates/sol-type-parser/src/error.rs +++ b/crates/sol-type-parser/src/error.rs @@ -8,8 +8,7 @@ pub type Result = core::result::Result; #[derive(Clone, PartialEq, Eq)] pub struct Error(Repr); -#[cfg(feature = "std")] -impl std::error::Error for Error {} +impl core::error::Error for Error {} impl fmt::Debug for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/crates/sol-type-parser/src/input.rs b/crates/sol-type-parser/src/input.rs index 475304d6e..6af47b2d4 100644 --- a/crates/sol-type-parser/src/input.rs +++ b/crates/sol-type-parser/src/input.rs @@ -18,8 +18,7 @@ impl fmt::Display for CustomError { } } -#[cfg(feature = "std")] -impl std::error::Error for CustomError {} +impl core::error::Error for CustomError {} pub type Input<'a> = winnow::Stateful<&'a str, RecursionCheck>; diff --git a/crates/sol-types/src/types/error.rs b/crates/sol-types/src/types/error.rs index 25046d568..4ffbd003e 100644 --- a/crates/sol-types/src/types/error.rs +++ b/crates/sol-types/src/types/error.rs @@ -103,8 +103,7 @@ impl fmt::Display for Revert { } } -#[cfg(feature = "std")] -impl std::error::Error for Revert {} +impl core::error::Error for Revert {} impl AsRef for Revert { #[inline] @@ -264,8 +263,7 @@ impl fmt::Display for Panic { } } -#[cfg(feature = "std")] -impl std::error::Error for Panic {} +impl core::error::Error for Panic {} impl SolError for Panic { type Parameters<'a> = (crate::sol_data::Uint<256>,); diff --git a/crates/sol-types/src/types/interface/mod.rs b/crates/sol-types/src/types/interface/mod.rs index 0491748be..a054cf1e3 100644 --- a/crates/sol-types/src/types/interface/mod.rs +++ b/crates/sol-types/src/types/interface/mod.rs @@ -2,9 +2,6 @@ use crate::{alloc::string::ToString, Error, Panic, Result, Revert, SolError}; use alloc::{string::String, vec::Vec}; use core::{convert::Infallible, fmt, iter::FusedIterator, marker::PhantomData}; -#[cfg(feature = "std")] -use std::error::Error as StdError; - mod event; pub use event::SolEventInterface; @@ -211,10 +208,9 @@ impl fmt::Display for ContractError { } } -#[cfg(feature = "std")] -impl StdError for ContractError { +impl core::error::Error for ContractError { #[inline] - fn source(&self) -> Option<&(dyn StdError + 'static)> { + fn source(&self) -> Option<&(dyn core::error::Error + 'static)> { match self { Self::CustomError(error) => Some(error), Self::Panic(panic) => Some(panic), diff --git a/crates/syn-solidity/tests/contracts.rs b/crates/syn-solidity/tests/contracts.rs index c9fb26ea0..3b65b2616 100644 --- a/crates/syn-solidity/tests/contracts.rs +++ b/crates/syn-solidity/tests/contracts.rs @@ -100,7 +100,7 @@ impl Drop for GitPatcher<'_> { } } -fn parse_file(path: &Path) -> Result> { +fn parse_file(path: &Path) -> Result> { let solidity = fs::read_to_string(path)?; syn::parse_str(&solidity).map_err(Into::into) }