hashes: Add From<Infallible> for error types
What changed, and why it matters
This commit adds a standard Rust trait implementation that lets two error types be automatically converted from the 'Infallible' type (a type that can never actually exist). It is a routine ergonomic improvement and does not fix any security bug or change runtime behavior.
No security action needed. Treat as a normal maintenance/API-ergonomics commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds impl From<Infallible> for MaxLengthError and impl From<Infallible> for MidstateError in rust-bitcoin’s hashes crate. Infallible is an uninhabited type, so these impls can never be invoked at runtime; they only satisfy trait bounds and allow ? propagation in generic contexts. No existing code paths, validation logic, or cryptographic operations are modified.
Changed components
hashes/src/hkdf/mod.rshashes/src/sha256/mod.rsInspect captured patch +10 / −0
diff --git a/hashes/src/hkdf/mod.rs b/hashes/src/hkdf/mod.rs
index 2129b53e..351fed52 100644
--- a/hashes/src/hkdf/mod.rs
+++ b/hashes/src/hkdf/mod.rs
@@ -145,6 +145,7 @@ impl<T: HashEngine> fmt::Debug for Hkdf<T> {
/// Error types for the HKDF hash.
pub mod error {
+ use core::convert::Infallible;
use core::fmt;
/// Size of output exceeds maximum length allowed.
@@ -153,6 +154,10 @@ pub mod error {
pub(super) max: usize,
}
+ impl From<Infallible> for MaxLengthError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for MaxLengthError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "exceeds {} byte max output material limit", self.max)
diff --git a/hashes/src/sha256/mod.rs b/hashes/src/sha256/mod.rs
index bcac3ddc..e696fe66 100644
--- a/hashes/src/sha256/mod.rs
+++ b/hashes/src/sha256/mod.rs
@@ -266,6 +266,7 @@ impl convert::AsRef<[u8]> for Midstate {
/// Error types for the SHA256 hash.
pub mod error {
+ use core::convert::Infallible;
use core::fmt;
use super::{Midstate, BLOCK_SIZE};
@@ -292,6 +293,10 @@ pub mod error {
}
}
+ impl From<Infallible> for MidstateError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for MidstateError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
Why this scored 16/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.