Add From<Infallible> to sighash errors
What changed, and why it matters
This commit adds standard Rust trait implementations that allow certain Bitcoin signature-hash error types to be created from the Infallible type. Infallible is a type that can never actually exist, so these conversions can never be invoked at runtime. The change is purely an ergonomic improvement for generic programming and has no security relevance.
No security action required. This is a routine API-ergonomics change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds impl From<Infallible> for three error structs in crypto/src/sighash.rs: InvalidSighashTypeError, NonStandardSighashTypeError, and SighashTypeParseError. Because Infallible has no values, the implementation bodies are empty match never {} expressions. This is a common Rust pattern to make error types composable in generic contexts where From<Infallible> is required as a bound. No logic, parsing, cryptography, or error handling behavior changes.
Changed components
crypto/src/sighash.rs error moduleInspect captured patch +13 / −0
diff --git a/crypto/src/sighash.rs b/crypto/src/sighash.rs
index 83186614..bc634da1 100644
--- a/crypto/src/sighash.rs
+++ b/crypto/src/sighash.rs
@@ -227,6 +227,7 @@ impl From<EcdsaSighashType> for TapSighashType {
/// Error types for signature hashing.
pub mod error {
+ use core::convert::Infallible;
use core::fmt;
use internals::error::InputString;
@@ -235,6 +236,10 @@ pub mod error {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InvalidSighashTypeError(pub(crate) u32);
+ impl From<Infallible> for InvalidSighashTypeError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for InvalidSighashTypeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "invalid sighash type {}", self.0)
@@ -254,6 +259,10 @@ pub mod error {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct NonStandardSighashTypeError(pub(crate) u32);
+ impl From<Infallible> for NonStandardSighashTypeError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for NonStandardSighashTypeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "non-standard sighash type {}", self.0)
@@ -278,6 +287,10 @@ pub mod error {
pub(super) unrecognized: InputString,
}
+ impl From<Infallible> for SighashTypeParseError {
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for SighashTypeParseError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.unrecognized.display_cannot_parse("SIGHASH string"))
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.