Replace Result<(), fmt::Error> with fmt::Result
What changed, and why it matters
This commit is a purely cosmetic code cleanup. It replaces the longer way of writing Rust's formatting error return type, `Result<(), fmt::Error>`, with the standard shorter alias, `fmt::Result`. The actual behavior of the code does not change at all.
No security action needed. This is a safe refactoring commit.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit performs a type-alias substitution across 9 files. core::fmt::Result is defined as pub type Result = core::result::Result<(), core::fmt::Error>;, so every changed signature is semantically identical. No logic, control flow, error handling, or trait implementations were modified. This is a refactoring change with no functional or security effect.
Changed components
base58/src/lib.rsbitcoin/src/address/mod.rsbitcoin/src/bip158.rsbitcoin/src/blockdata/opcodes.rsbitcoin/src/blockdata/script/builder.rsio/src/error.rsnetwork/src/lib.rsp2p/src/lib.rsunits/src/internal_macros.rsInspect captured patch +22 / −22
diff --git a/base58/src/lib.rs b/base58/src/lib.rs
index 0f8e3c9f..c84c589f 100644
--- a/base58/src/lib.rs
+++ b/base58/src/lib.rs
@@ -222,7 +222,7 @@ impl<const N: usize> Buffer for ArrayVec<u8, N> {
fn slice_mut(&mut self) -> &mut [u8] { self.as_mut_slice() }
}
-fn format_iter<I, W>(writer: &mut W, data: I, buf: &mut impl Buffer) -> Result<(), fmt::Error>
+fn format_iter<I, W>(writer: &mut W, data: I, buf: &mut impl Buffer) -> fmt::Result
where
I: Iterator<Item = u8> + Clone,
W: fmt::Write,
diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs
index d90ff2a1..c591599f 100644
--- a/bitcoin/src/address/mod.rs
+++ b/bitcoin/src/address/mod.rs
@@ -743,7 +743,7 @@ impl Address {
/// # let address = ADDRESS.parse::<bitcoin::Address<_>>().unwrap().assume_checked();
/// # let mut writer = String::new();
/// # // magic trick to make error handling look better
- /// # (|| -> Result<(), core::fmt::Error> {
+ /// # (|| -> core::fmt::Result {
///
/// write!(writer, "{:#}", address)?;
///
diff --git a/bitcoin/src/bip158.rs b/bitcoin/src/bip158.rs
index 92c7789f..c9d2b7a9 100644
--- a/bitcoin/src/bip158.rs
+++ b/bitcoin/src/bip158.rs
@@ -71,7 +71,7 @@ impl From<Infallible> for Error {
}
impl fmt::Display for Error {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Self::UtxoMissing(ref coin) => write!(f, "unresolved UTXO {}", coin),
Self::Io(ref e) => write_err!(f, "I/O error"; e),
diff --git a/bitcoin/src/blockdata/opcodes.rs b/bitcoin/src/blockdata/opcodes.rs
index d69c4790..ac8dfa02 100644
--- a/bitcoin/src/blockdata/opcodes.rs
+++ b/bitcoin/src/blockdata/opcodes.rs
@@ -509,7 +509,7 @@ impl From<u8> for Opcode {
}
impl fmt::Debug for Opcode {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fmt::Display::fmt(self, f) }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self, f) }
}
#[cfg(feature = "serde")]
diff --git a/bitcoin/src/blockdata/script/builder.rs b/bitcoin/src/blockdata/script/builder.rs
index e640827b..8dac2bf2 100644
--- a/bitcoin/src/blockdata/script/builder.rs
+++ b/bitcoin/src/blockdata/script/builder.rs
@@ -209,5 +209,5 @@ impl<T> fmt::Display for Builder<T> {
}
impl<T> fmt::Debug for Builder<T> {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fmt::Display::fmt(self, f) }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self, f) }
}
diff --git a/io/src/error.rs b/io/src/error.rs
index ec9262b3..3ebde2a4 100644
--- a/io/src/error.rs
+++ b/io/src/error.rs
@@ -67,7 +67,7 @@ impl From<ErrorKind> for Error {
}
impl fmt::Display for Error {
- fn fmt(&self, fmt: &mut fmt::Formatter) -> core::result::Result<(), core::fmt::Error> {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_fmt(format_args!("I/O Error: {}", self.kind.description()))?;
#[cfg(any(feature = "alloc", feature = "std"))]
if let Some(e) = &self.error {
diff --git a/network/src/lib.rs b/network/src/lib.rs
index 14a7eb5d..43004d26 100644
--- a/network/src/lib.rs
+++ b/network/src/lib.rs
@@ -242,7 +242,7 @@ pub mod as_core_arg {
pub struct ParseNetworkError(InputString);
impl fmt::Display for ParseNetworkError {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// Outputs 'failed to parse <input string> as network'.
write!(f, "{}", self.0.display_cannot_parse("network"))
}
diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs
index 33386bbb..66de9a3a 100644
--- a/p2p/src/lib.rs
+++ b/p2p/src/lib.rs
@@ -475,18 +475,18 @@ impl TryFrom<Magic> for Network {
}
impl fmt::Display for Magic {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hex::fmt_hex_exact!(f, 4, &self.0, hex::Case::Lower)?;
Ok(())
}
}
impl fmt::Debug for Magic {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { fmt::Display::fmt(self, f) }
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(self, f) }
}
impl fmt::LowerHex for Magic {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hex::fmt_hex_exact!(f, 4, &self.0, hex::Case::Lower)?;
Ok(())
}
@@ -494,7 +494,7 @@ impl fmt::LowerHex for Magic {
impl_to_hex_from_lower_hex!(Magic, |_| 8);
impl fmt::UpperHex for Magic {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
hex::fmt_hex_exact!(f, 4, &self.0, hex::Case::Upper)?;
Ok(())
}
@@ -617,7 +617,7 @@ pub struct ParseMagicError {
}
impl fmt::Display for ParseMagicError {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "failed to parse {} as network magic", self.magic)
}
}
@@ -633,7 +633,7 @@ impl std::error::Error for ParseMagicError {
pub struct UnknownMagicError(Magic);
impl fmt::Display for UnknownMagicError {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "unknown network magic {}", self.0)
}
}
@@ -649,7 +649,7 @@ impl std::error::Error for UnknownMagicError {
pub struct UnknownNetworkError(Network);
impl fmt::Display for UnknownNetworkError {
- fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "unknown network {}", self.0)
}
}
diff --git a/units/src/internal_macros.rs b/units/src/internal_macros.rs
index 3d25ac9c..a9b049df 100644
--- a/units/src/internal_macros.rs
+++ b/units/src/internal_macros.rs
@@ -186,50 +186,50 @@ pub(crate) use impl_div_assign;
macro_rules! impl_fmt_traits_for_u32_wrapper {
($ty:ident) => {
impl core::fmt::LowerHex for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::LowerHex::fmt(&self.0, f)
}
}
impl core::fmt::UpperHex for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::UpperHex::fmt(&self.0, f)
}
}
impl core::fmt::Octal for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Octal::fmt(&self.0, f)
}
}
impl core::fmt::Binary for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Binary::fmt(&self.0, f)
}
}
};
($ty:ident, $fn:ident) => {
impl core::fmt::LowerHex for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::LowerHex::fmt(&self.$fn(), f)
}
}
impl core::fmt::UpperHex for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::UpperHex::fmt(&self.$fn(), f)
}
}
impl core::fmt::Octal for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Octal::fmt(&self.$fn(), f)
}
}
impl core::fmt::Binary for $ty {
- fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
+ fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
core::fmt::Binary::fmt(&self.$fn(), f)
}
}
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.