diff --git a/hashes/src/error.rs b/hashes/src/error.rs index bac9ba649..ce2c82af2 100644 --- a/hashes/src/error.rs +++ b/hashes/src/error.rs @@ -2,13 +2,16 @@ //! Error code for the `hashes` crate. +use core::convert::Infallible; use core::fmt; /// Attempted to create a hash from an invalid length slice. #[derive(Debug, Clone, PartialEq, Eq)] pub struct FromSliceError(pub(crate) FromSliceErrorInner); -impl_from_infallible!(FromSliceError); +impl From for FromSliceError { + fn from(never: Infallible) -> Self { match never {} } +} impl FromSliceError { /// Returns the expected slice length. @@ -25,7 +28,9 @@ pub(crate) struct FromSliceErrorInner { pub(crate) got: usize, } -impl_from_infallible!(FromSliceErrorInner); +impl From for FromSliceErrorInner { + fn from(never: Infallible) -> Self { match never {} } +} impl fmt::Display for FromSliceError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -35,19 +40,3 @@ impl fmt::Display for FromSliceError { #[cfg(feature = "std")] impl std::error::Error for FromSliceError {} - -/// Derives `From` for the given type. -// This is a duplicate of `internals::impl_from_infallible`, see there for complete docs. -#[doc(hidden)] -macro_rules! impl_from_infallible { - ( $name:ident $(< $( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+ >)? ) => { - impl $(< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? - From - for $name - $(< $( $lt ),+ >)? - { - fn from(never: core::convert::Infallible) -> Self { match never {} } - } - } -} -pub(crate) use impl_from_infallible; diff --git a/primitives/src/script/mod.rs b/primitives/src/script/mod.rs index 2045d01eb..8c240ddc3 100644 --- a/primitives/src/script/mod.rs +++ b/primitives/src/script/mod.rs @@ -8,6 +8,7 @@ mod borrowed; mod owned; use core::cmp::Ordering; +use core::convert::Infallible; use core::fmt; use core::ops::{Deref, DerefMut}; @@ -158,7 +159,9 @@ pub struct RedeemScriptSizeError { pub size: usize, } -internals::impl_from_infallible!(RedeemScriptSizeError); +impl From for RedeemScriptSizeError { + fn from(never: Infallible) -> Self { match never {} } +} impl fmt::Display for RedeemScriptSizeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -176,7 +179,9 @@ pub struct WitnessScriptSizeError { pub size: usize, } -internals::impl_from_infallible!(WitnessScriptSizeError); +impl From for WitnessScriptSizeError { + fn from(never: Infallible) -> Self { match never {} } +} impl fmt::Display for WitnessScriptSizeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs index 9b950da01..4424103f4 100644 --- a/primitives/src/transaction.rs +++ b/primitives/src/transaction.rs @@ -12,6 +12,7 @@ #[cfg(feature = "alloc")] use core::cmp; +use core::convert::Infallible; use core::fmt; #[cfg(feature = "arbitrary")] @@ -444,7 +445,9 @@ pub enum ParseOutPointError { } #[cfg(feature = "alloc")] -internals::impl_from_infallible!(ParseOutPointError); +impl From for ParseOutPointError { + fn from(never: Infallible) -> Self { match never {} } +} #[cfg(feature = "alloc")] impl fmt::Display for ParseOutPointError { diff --git a/units/src/amount/error.rs b/units/src/amount/error.rs index d90e70c5a..62e03a306 100644 --- a/units/src/amount/error.rs +++ b/units/src/amount/error.rs @@ -2,6 +2,7 @@ //! Error types for bitcoin amounts. +use core::convert::Infallible; use core::fmt; use internals::error::InputString; @@ -23,8 +24,13 @@ pub(crate) enum ParseErrorInner { MissingDenomination(MissingDenominationError), } -internals::impl_from_infallible!(ParseError); -internals::impl_from_infallible!(ParseErrorInner); +impl From for ParseError { + fn from(never: Infallible) -> Self { match never {} } +} + +impl From for ParseErrorInner { + fn from(never: Infallible) -> Self { match never {} } +} impl From for ParseError { fn from(e: ParseAmountError) -> Self { Self(ParseErrorInner::Amount(e)) } @@ -114,8 +120,13 @@ impl From for ParseAmountError { } } -internals::impl_from_infallible!(ParseAmountError); -internals::impl_from_infallible!(ParseAmountErrorInner); +impl From for ParseAmountError { + fn from(never: Infallible) -> Self { match never {} } +} + +impl From for ParseAmountErrorInner { + fn from(never: Infallible) -> Self { match never {} } +} impl fmt::Display for ParseAmountError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -318,7 +329,9 @@ pub enum ParseDenominationError { PossiblyConfusing(PossiblyConfusingDenominationError), } -internals::impl_from_infallible!(ParseDenominationError); +impl From for ParseDenominationError { + fn from(never: Infallible) -> Self { match never {} } +} impl fmt::Display for ParseDenominationError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { diff --git a/units/src/amount/mod.rs b/units/src/amount/mod.rs index f340b90da..79d2e7ec0 100644 --- a/units/src/amount/mod.rs +++ b/units/src/amount/mod.rs @@ -17,6 +17,7 @@ mod unsigned; mod verification; use core::cmp::Ordering; +use core::convert::Infallible; use core::fmt; use core::str::FromStr; @@ -292,7 +293,9 @@ enum InnerParseError { InvalidCharacter(InvalidCharacterError), } -internals::impl_from_infallible!(InnerParseError); +impl From for InnerParseError { + fn from(never: Infallible) -> Self { match never {} } +} impl InnerParseError { fn convert(self, is_signed: bool) -> ParseAmountError { diff --git a/units/src/locktime/absolute.rs b/units/src/locktime/absolute.rs index 25de4f797..966f6e129 100644 --- a/units/src/locktime/absolute.rs +++ b/units/src/locktime/absolute.rs @@ -2,6 +2,7 @@ //! Provides [`Height`] and [`Time`] types used by the `rust-bitcoin` `absolute::LockTime` type. +use core::convert::Infallible; use core::fmt; #[cfg(feature = "arbitrary")] @@ -307,7 +308,9 @@ enum ParseError { Conversion(i64), } -internals::impl_from_infallible!(ParseError); +impl From for ParseError { + fn from(never: Infallible) -> Self { match never {} } +} impl ParseError { fn invalid_int>(s: S) -> impl FnOnce(core::num::ParseIntError) -> Self { diff --git a/units/src/parse.rs b/units/src/parse.rs index ec36d4b94..6d3b156b6 100644 --- a/units/src/parse.rs +++ b/units/src/parse.rs @@ -2,6 +2,7 @@ //! Parsing utilities. +use core::convert::Infallible; use core::fmt; use core::str::FromStr; @@ -313,8 +314,13 @@ enum PrefixedHexErrorInner { ParseInt(ParseIntError), } -internals::impl_from_infallible!(PrefixedHexError); -internals::impl_from_infallible!(PrefixedHexErrorInner); +impl From for PrefixedHexError { + fn from(never: Infallible) -> Self { match never {} } +} + +impl From for PrefixedHexErrorInner { + fn from(never: Infallible) -> Self { match never {} } +} impl fmt::Display for PrefixedHexError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -359,8 +365,13 @@ enum UnprefixedHexErrorInner { ParseInt(ParseIntError), } -internals::impl_from_infallible!(UnprefixedHexError); -internals::impl_from_infallible!(UnprefixedHexErrorInner); +impl From for UnprefixedHexError { + fn from(never: Infallible) -> Self { match never {} } +} + +impl From for UnprefixedHexErrorInner { + fn from(never: Infallible) -> Self { match never {} } +} impl fmt::Display for UnprefixedHexError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {