What changed, and why it matters
This commit is a routine code-quality fix. It adds the standard Rust error boilerplate (Display and std::error::Error implementations) to a missing-denomination error type and reorders similar boilerplate in another file. There is no security-relevant change.
No security action required; treat as normal maintenance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch implements fmt::Display and std::error::Error for MissingDenominationError in units/src/amount/error.rs, and updates ParseError::Display/source() to delegate to it. It also moves an impl From<Infallible> block after an inherent impl block in units/src/locktime/relative/error.rs. These are cosmetic/ergonomic improvements only; no parsing logic, bounds checking, or cryptographic code is changed.
Changed components
units/src/amount/error.rsunits/src/locktime/relative/error.rsInspect captured patch +18 / −8
diff --git a/units/src/amount/error.rs b/units/src/amount/error.rs
index 7f098334..1f4b23ba 100644
--- a/units/src/amount/error.rs
+++ b/units/src/amount/error.rs
@@ -39,8 +39,7 @@ impl fmt::Display for ParseError {
ParseErrorInner::Amount(ref e) => write_err!(f, "invalid amount"; e),
ParseErrorInner::Denomination(ref e) => write_err!(f, "invalid denomination"; e),
// We consider this to not be a source because it currently doesn't contain useful info.
- ParseErrorInner::MissingDenomination(_) =>
- f.write_str("the input doesn't contain a denomination"),
+ ParseErrorInner::MissingDenomination(ref e) => write_err!(f, "missing denomination"; e),
}
}
}
@@ -52,7 +51,7 @@ impl std::error::Error for ParseError {
ParseErrorInner::Amount(ref e) => Some(e),
ParseErrorInner::Denomination(ref e) => Some(e),
// We consider this to not be a source because it currently doesn't contain useful info.
- ParseErrorInner::MissingDenomination(_) => None,
+ ParseErrorInner::MissingDenomination(ref e) => Some(e),
}
}
}
@@ -375,6 +374,17 @@ impl From<Infallible> for MissingDenominationError {
fn from(never: Infallible) -> Self { match never {} }
}
+impl fmt::Display for MissingDenominationError {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "the input does not contain a denomination")
+ }
+}
+
+#[cfg(feature = "std")]
+impl std::error::Error for MissingDenominationError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+}
+
/// Error returned when parsing an unknown denomination.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
@@ -618,7 +628,7 @@ mod tests {
let e = "123".parse::<Amount>().unwrap_err();
assert!(!e.to_string().is_empty());
#[cfg(feature = "std")]
- assert!(e.source().is_none());
+ assert!(e.source().is_some());
#[cfg(feature = "encoding")]
{
diff --git a/units/src/locktime/relative/error.rs b/units/src/locktime/relative/error.rs
index c8243e6e..9ab5daee 100644
--- a/units/src/locktime/relative/error.rs
+++ b/units/src/locktime/relative/error.rs
@@ -14,10 +14,6 @@ use super::{NumberOf512Seconds, NumberOfBlocks};
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct DisabledLockTimeError(pub(super) u32);
-impl From<Infallible> for DisabledLockTimeError {
- fn from(never: Infallible) -> Self { match never {} }
-}
-
impl DisabledLockTimeError {
/// Accessor for the `u32` whose "disable" flag was set, preventing
/// it from being parsed as a relative locktime.
@@ -25,6 +21,10 @@ impl DisabledLockTimeError {
pub fn disabled_locktime_value(&self) -> u32 { self.0 }
}
+impl From<Infallible> for DisabledLockTimeError {
+ fn from(never: Infallible) -> Self { match never {} }
+}
+
impl fmt::Display for DisabledLockTimeError {
#[inline]
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.