consensus_encoding: Add explicit None return impl for std::error::Error
What changed, and why it matters
This commit is a minor code-clarity change. It rewrites two standard Rust error trait implementations to explicitly state that these errors have no underlying cause, instead of relying on Rust's automatic default. There is no functional change and no security relevance.
No action required. This is a non-functional documentation-style refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch replaces two blanket impl std::error::Error for ... {} blocks with explicit source() methods that return None. Because std::error::Error provides a default source() implementation that already returns None, the compiled behavior is identical. The change only affects readability and maintainability.
Changed components
consensus_encoding/src/error.rsInspect captured patch +6 / −2
diff --git a/consensus_encoding/src/error.rs b/consensus_encoding/src/error.rs
index e8a89021..d8643ff0 100644
--- a/consensus_encoding/src/error.rs
+++ b/consensus_encoding/src/error.rs
@@ -194,7 +194,9 @@ impl core::fmt::Display for LengthPrefixExceedsMaxError {
}
#[cfg(feature = "std")]
-impl std::error::Error for LengthPrefixExceedsMaxError {}
+impl std::error::Error for LengthPrefixExceedsMaxError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+}
/// The error returned by the [`ByteVecDecoder`].
#[cfg(feature = "alloc")]
@@ -311,7 +313,9 @@ impl fmt::Display for UnexpectedEofError {
}
#[cfg(feature = "std")]
-impl std::error::Error for UnexpectedEofError {}
+impl std::error::Error for UnexpectedEofError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
+}
/// Helper macro to define an error type for a `DecoderN`.
macro_rules! define_decoder_n_error {
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.