Skip to content

Commit

Permalink
chore: use core::error::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
Evalir committed Oct 23, 2024
1 parent 85abe59 commit f3da7cf
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 21 deletions.
3 changes: 1 addition & 2 deletions crates/dyn-abi/src/coerce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions crates/primitives/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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<BITS, LIMBS> {
fn accepts(ty: &Type) -> bool {
Expand Down
3 changes: 1 addition & 2 deletions crates/primitives/src/signed/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions crates/sol-type-parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ pub type Result<T, E = Error> = core::result::Result<T, E>;
#[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 {
Expand Down
3 changes: 1 addition & 2 deletions crates/sol-type-parser/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;

Expand Down
6 changes: 2 additions & 4 deletions crates/sol-types/src/types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str> for Revert {
#[inline]
Expand Down Expand Up @@ -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>,);
Expand Down
8 changes: 2 additions & 6 deletions crates/sol-types/src/types/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -211,10 +208,9 @@ impl<T: fmt::Display> fmt::Display for ContractError<T> {
}
}

#[cfg(feature = "std")]
impl<T: StdError + 'static> StdError for ContractError<T> {
impl<T: core::error::Error + 'static> core::error::Error for ContractError<T> {
#[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),
Expand Down
2 changes: 1 addition & 1 deletion crates/syn-solidity/tests/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Drop for GitPatcher<'_> {
}
}

fn parse_file(path: &Path) -> Result<File, Box<dyn std::error::Error>> {
fn parse_file(path: &Path) -> Result<File, Box<dyn core::error::Error>> {
let solidity = fs::read_to_string(path)?;
syn::parse_str(&solidity).map_err(Into::into)
}
Expand Down

0 comments on commit f3da7cf

Please sign in to comment.