Replace Debug impl with derive on ParsePrimitiveError wrappers
What changed, and why it matters
This commit is a routine code cleanup. It removes hand-written Debug formatting code for three error types and instead lets Rust automatically generate Debug, Clone, PartialEq, and Eq behavior. There is no security-relevant change here.
No action required. This is a non-security refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch replaces manual impl fmt::Debug blocks for ParseBlockError, ParseHeaderError, and ParseTransactionError with #[derive(Debug, Clone, PartialEq, Eq)]. The derived Debug output will now include the wrapper type name (e.g., ParseBlockError(...)), whereas the manual implementation delegated directly to the inner ParsePrimitiveError Debug output. This is a behavioral change in debug formatting only and does not affect parsing logic, error handling, or any security property.
Changed components
primitives/src/block.rsprimitives/src/transaction.rsInspect captured patch +3 / −15
diff --git a/primitives/src/block.rs b/primitives/src/block.rs
index b507068d..f3b03d8e 100644
--- a/primitives/src/block.rs
+++ b/primitives/src/block.rs
@@ -311,6 +311,7 @@ impl<V: Validation> fmt::UpperHex for Block<V> {
/// An error that occurs during parsing of a [`Block`] from a hex string.
#[cfg(all(feature = "hex", feature = "alloc"))]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseBlockError(ParsePrimitiveError<Block>);
#[cfg(all(feature = "hex", feature = "alloc"))]
@@ -318,11 +319,6 @@ impl From<Infallible> for ParseBlockError {
fn from(never: Infallible) -> Self { match never {} }
}
-#[cfg(all(feature = "hex", feature = "alloc"))]
-impl fmt::Debug for ParseBlockError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.0, f) }
-}
-
#[cfg(all(feature = "hex", feature = "alloc"))]
impl fmt::Display for ParseBlockError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -618,6 +614,7 @@ impl fmt::Debug for Header {
/// An error that occurs during parsing of a [`Header`] from a hex string.
#[cfg(feature = "hex")]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseHeaderError(ParsePrimitiveError<Header>);
#[cfg(feature = "hex")]
@@ -625,11 +622,6 @@ impl From<Infallible> for ParseHeaderError {
fn from(never: Infallible) -> Self { match never {} }
}
-#[cfg(feature = "hex")]
-impl fmt::Debug for ParseHeaderError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.0, f) }
-}
-
#[cfg(feature = "hex")]
impl fmt::Display for ParseHeaderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
diff --git a/primitives/src/transaction.rs b/primitives/src/transaction.rs
index 4072635b..57a3d308 100644
--- a/primitives/src/transaction.rs
+++ b/primitives/src/transaction.rs
@@ -408,6 +408,7 @@ impl fmt::UpperHex for Transaction {
/// An error that occurs during parsing of a [`Transaction`] from a hex string.
#[cfg(all(feature = "hex", feature = "alloc"))]
+#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ParseTransactionError(ParsePrimitiveError<Transaction>);
#[cfg(all(feature = "hex", feature = "alloc"))]
@@ -415,11 +416,6 @@ impl From<Infallible> for ParseTransactionError {
fn from(never: Infallible) -> Self { match never {} }
}
-#[cfg(all(feature = "hex", feature = "alloc"))]
-impl fmt::Debug for ParseTransactionError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(&self.0, f) }
-}
-
#[cfg(all(feature = "hex", feature = "alloc"))]
impl fmt::Display for ParseTransactionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.