style: use Self:: instead of type aliases in error impls

Use  instead of 'use FooError as E' when pattern matching
on the same type in Display/Error trait implementations.
This commit is contained in:
frankomosh 2025-05-22 20:12:11 +03:00
parent 855299ab7e
commit 0a0e23fedf
3 changed files with 20 additions and 29 deletions

View File

@ -471,14 +471,12 @@ impl From<Infallible> for ParseOutPointError {
#[cfg(feature = "hex")]
impl fmt::Display for ParseOutPointError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ParseOutPointError as E;
match *self {
E::Txid(ref e) => write_err!(f, "error parsing TXID"; e),
E::Vout(ref e) => write_err!(f, "error parsing vout"; e),
E::Format => write!(f, "OutPoint not in <txid>:<vout> format"),
E::TooLong => write!(f, "vout should be at most 10 digits"),
E::VoutNotCanonical => write!(f, "no leading zeroes or + allowed in vout part"),
Self::Txid(ref e) => write_err!(f, "error parsing TXID"; e),
Self::Vout(ref e) => write_err!(f, "error parsing vout"; e),
Self::Format => write!(f, "OutPoint not in <txid>:<vout> format"),
Self::TooLong => write!(f, "vout should be at most 10 digits"),
Self::VoutNotCanonical => write!(f, "no leading zeroes or + allowed in vout part"),
}
}
}
@ -487,12 +485,10 @@ impl fmt::Display for ParseOutPointError {
#[cfg(feature = "hex")]
impl std::error::Error for ParseOutPointError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use ParseOutPointError as E;
match self {
E::Txid(e) => Some(e),
E::Vout(e) => Some(e),
E::Format | E::TooLong | E::VoutNotCanonical => None,
Self::Txid(e) => Some(e),
Self::Vout(e) => Some(e),
Self::Format | Self::TooLong | Self::VoutNotCanonical => None,
}
}
}

View File

@ -337,11 +337,9 @@ impl From<Infallible> for ParseDenominationError {
impl fmt::Display for ParseDenominationError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use ParseDenominationError as E;
match *self {
E::Unknown(ref e) => write_err!(f, "denomination parse error"; e),
E::PossiblyConfusing(ref e) => write_err!(f, "denomination parse error"; e),
Self::Unknown(ref e) => write_err!(f, "denomination parse error"; e),
Self::PossiblyConfusing(ref e) => write_err!(f, "denomination parse error"; e),
}
}
}
@ -349,10 +347,9 @@ impl fmt::Display for ParseDenominationError {
#[cfg(feature = "std")]
impl std::error::Error for ParseDenominationError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use ParseDenominationError as E;
match *self {
E::Unknown(_) | E::PossiblyConfusing(_) => None,
Self::Unknown(_) | Self::PossiblyConfusing(_) => None,
}
}
}

View File

@ -377,10 +377,9 @@ impl ParseError {
) -> fmt::Result {
use core::num::IntErrorKind;
use ParseError as E;
match self {
E::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
Self::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
if *source.kind() == IntErrorKind::PosOverflow =>
{
// Outputs "failed to parse <input_string> as absolute Height/MedianTimePast (<subject> is above limit <upper_bound>)"
@ -392,7 +391,7 @@ impl ParseError {
upper_bound
)
}
E::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
Self::ParseInt(ParseIntError { input, bits: _, is_signed: _, source })
if *source.kind() == IntErrorKind::NegOverflow =>
{
// Outputs "failed to parse <input_string> as absolute Height/MedianTimePast (<subject> is below limit <lower_bound>)"
@ -404,7 +403,7 @@ impl ParseError {
lower_bound
)
}
E::ParseInt(ParseIntError { input, bits: _, is_signed: _, source: _ }) => {
Self::ParseInt(ParseIntError { input, bits: _, is_signed: _, source: _ }) => {
write!(
f,
"{} ({})",
@ -412,10 +411,10 @@ impl ParseError {
subject
)
}
E::Conversion(value) if *value < i64::from(lower_bound) => {
Self::Conversion(value) if *value < i64::from(lower_bound) => {
write!(f, "{} {} is below limit {}", subject, value, lower_bound)
}
E::Conversion(value) => {
Self::Conversion(value) => {
write!(f, "{} {} is above limit {}", subject, value, upper_bound)
}
}
@ -426,17 +425,16 @@ impl ParseError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use core::num::IntErrorKind;
use ParseError as E;
match self {
E::ParseInt(ParseIntError { source, .. })
Self::ParseInt(ParseIntError { source, .. })
if *source.kind() == IntErrorKind::PosOverflow =>
None,
E::ParseInt(ParseIntError { source, .. })
Self::ParseInt(ParseIntError { source, .. })
if *source.kind() == IntErrorKind::NegOverflow =>
None,
E::ParseInt(ParseIntError { source, .. }) => Some(source),
E::Conversion(_) => None,
Self::ParseInt(ParseIntError { source, .. }) => Some(source),
Self::Conversion(_) => None,
}
}
}