Merge rust-bitcoin/rust-bitcoin#4544: use Self:: instead of type aliases in error impls

0a0e23fedf style: use Self:: instead of type aliases in error impls (frankomosh)

Pull request description:

  Replace `use FooError as E` with `Self::` , during pattern matching
  on the same type in Display/Error trait implementations.

  close #4536

ACKs for top commit:
  tcharding:
    ACK 0a0e23fedf
  apoelstra:
    ACK 0a0e23fedf3552df677b379d86a1e0ac6b063152; successfully ran local tests

Tree-SHA512: 25c45a890635f990afc3bc09096929f8793007852ac435f061348bff2bd79e3faabf034d1e1e277596f4f7365477f477798f1b1e0c4b918c5b0fa08f8c49e732
This commit is contained in:
merge-script 2025-05-23 12:39:35 +00:00
commit efae4cac8a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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,
}
}
}