Add From<Infallible> to all error types
What changed, and why it matters
This commit adds standard Rust helper code that lets several error types be automatically converted from Rust's Infallible type. Infallible is a type that can never actually exist, so these conversions are safe, cannot be triggered by user input, and have no security impact. It is a routine API ergonomics improvement.
No security action needed. Treat as a normal API-quality commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds impl From<Infallible> for ... to six error types in crypto/src/key.rs. Because Infallible has no values (enum Infallible {}), the implementation body match never {} is exhaustive and can never be executed at runtime. This is a standard Rust pattern to make error types compose better with generic code using ? and From conversions. There is no change to parsing, validation, cryptography, or memory handling.
Changed components
crypto/src/key.rs error types: UncompressedPublicKeyError, InvalidBase58PayloadLengthError, InvalidAddressVersionError, InvalidWifCompressionFlagError, ParseXOnlyPublicKeyError, TweakXOnlyPublicKeyErrorInspect captured patch +31 / −0
diff --git a/crypto/src/key.rs b/crypto/src/key.rs
index 196503c8..97767978 100644
--- a/crypto/src/key.rs
+++ b/crypto/src/key.rs
@@ -1724,6 +1724,11 @@ pub mod error {
#[non_exhaustive]
pub struct UncompressedPublicKeyError;
+ impl From<Infallible> for UncompressedPublicKeyError {
+ #[inline]
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for UncompressedPublicKeyError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1749,6 +1754,11 @@ pub mod error {
pub fn invalid_base58_payload_length(&self) -> usize { self.length }
}
+ impl From<Infallible> for InvalidBase58PayloadLengthError {
+ #[inline]
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for InvalidBase58PayloadLengthError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1779,6 +1789,11 @@ pub mod error {
pub fn invalid_address_version(&self) -> u8 { self.invalid }
}
+ impl From<Infallible> for InvalidAddressVersionError {
+ #[inline]
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for InvalidAddressVersionError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1807,6 +1822,12 @@ pub mod error {
pub fn invalid_compression_flag(&self) -> u8 { self.invalid }
}
+ #[cfg(feature = "alloc")]
+ impl From<Infallible> for InvalidWifCompressionFlagError {
+ #[inline]
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
#[cfg(feature = "alloc")]
impl fmt::Display for InvalidWifCompressionFlagError {
#[inline]
@@ -1831,6 +1852,11 @@ pub mod error {
InvalidXCoordinate,
}
+ impl From<Infallible> for ParseXOnlyPublicKeyError {
+ #[inline]
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for ParseXOnlyPublicKeyError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@@ -1863,6 +1889,11 @@ pub mod error {
ParityError,
}
+ impl From<Infallible> for TweakXOnlyPublicKeyError {
+ #[inline]
+ fn from(never: Infallible) -> Self { match never {} }
+ }
+
impl fmt::Display for TweakXOnlyPublicKeyError {
#[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.