What changed, and why it matters
This commit is a routine code cleanup. It removes unnecessary '?' operators in functions that already return a Result. The behavior of the code is unchanged; it just makes the code slightly cleaner and avoids a clippy lint warning.
No security action needed. This is a non-functional refactoring change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors six functions to return Result values directly instead of wrapping them in Ok(…) and then immediately unwrapping with ?. In Rust, ‘Ok(x?)’ is equivalent to ‘x’ when the function’s return type matches. The changes are purely idiomatic and have no functional effect on error handling, control flow, or return values.
Changed components
crypto/src/key.rsp2p/src/address.rsp2p/src/lib.rsprimitives/src/script/owned.rsunits/src/amount/signed.rsunits/src/amount/unsigned.rsInspect captured patch +11 / −13
diff --git a/crypto/src/key.rs b/crypto/src/key.rs
index d48b6c87..9030229c 100644
--- a/crypto/src/key.rs
+++ b/crypto/src/key.rs
@@ -871,7 +871,7 @@ impl FullPublicKey {
msg: secp256k1::Message,
sig: ecdsa::Signature,
) -> Result<(), secp256k1::Error> {
- Ok(secp256k1::ecdsa::verify(&sig.signature, msg, &self.to_inner())?)
+ secp256k1::ecdsa::verify(&sig.signature, msg, &self.to_inner())
}
}
diff --git a/p2p/src/address.rs b/p2p/src/address.rs
index 8e66ea7b..bd5edbb2 100644
--- a/p2p/src/address.rs
+++ b/p2p/src/address.rs
@@ -516,9 +516,10 @@ impl AddrV2Decoder {
fn to_fixed_size_slice<const N: usize>(
addr_bytes: Vec<u8>,
) -> Result<[u8; N], AddrV2DecoderError> {
- Ok(addr_bytes.try_into().map_err(|e: Vec<u8>| {
- AddrV2DecoderError::InvalidAddressLength { expected: N, got: e.len() }
- })?)
+ addr_bytes.try_into().map_err(|e: Vec<u8>| AddrV2DecoderError::InvalidAddressLength {
+ expected: N,
+ got: e.len(),
+ })
}
}
diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs
index c2c75302..59e4bdf5 100644
--- a/p2p/src/lib.rs
+++ b/p2p/src/lib.rs
@@ -146,7 +146,7 @@ impl encoding::Decoder for ProtocolVersionDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes).map_err(ProtocolVersionDecoderError)?)
+ self.0.push_bytes(bytes).map_err(ProtocolVersionDecoderError)
}
#[inline]
@@ -340,7 +340,7 @@ impl encoding::Decoder for ServiceFlagsDecoder {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes).map_err(ServiceFlagsDecoderError)?)
+ self.0.push_bytes(bytes).map_err(ServiceFlagsDecoderError)
}
#[inline]
diff --git a/primitives/src/script/owned.rs b/primitives/src/script/owned.rs
index 16d55022..6388f45c 100644
--- a/primitives/src/script/owned.rs
+++ b/primitives/src/script/owned.rs
@@ -199,7 +199,7 @@ impl<T> encoding::Decoder for ScriptBufDecoder<T> {
#[inline]
fn push_bytes(&mut self, bytes: &mut &[u8]) -> Result<bool, Self::Error> {
- Ok(self.0.push_bytes(bytes).map_err(ScriptBufDecoderError)?)
+ self.0.push_bytes(bytes).map_err(ScriptBufDecoderError)
}
#[inline]
diff --git a/units/src/amount/signed.rs b/units/src/amount/signed.rs
index 0fb4649e..772f2333 100644
--- a/units/src/amount/signed.rs
+++ b/units/src/amount/signed.rs
@@ -141,8 +141,7 @@ impl SignedAmount {
is_greater_than_max: true,
}))
})?;
- Ok(Self::from_sat(amount)
- .map_err(|e| ParseAmountError(ParseAmountErrorInner::OutOfRange(e)))?)
+ Self::from_sat(amount).map_err(|e| ParseAmountError(ParseAmountErrorInner::OutOfRange(e)))
}
/// Converts from a value expressing a decimal number of bitcoin to a [`SignedAmount`].
diff --git a/units/src/amount/unsigned.rs b/units/src/amount/unsigned.rs
index 26607827..1258f0ec 100644
--- a/units/src/amount/unsigned.rs
+++ b/units/src/amount/unsigned.rs
@@ -282,8 +282,7 @@ impl Amount {
pub fn from_sat_hex(s: &str) -> Result<Self, ParseAmountError> {
let amount = parse_int::hex_u64_prefixed(s)
.map_err(|e| ParseAmountError(ParseAmountErrorInner::PrefixedHex(e)))?;
- Ok(Self::from_sat(amount)
- .map_err(|e| ParseAmountError(ParseAmountErrorInner::OutOfRange(e)))?)
+ Self::from_sat(amount).map_err(|e| ParseAmountError(ParseAmountErrorInner::OutOfRange(e)))
}
/// Constructs a new `Amount` from an unprefixed hex string.
@@ -296,8 +295,7 @@ impl Amount {
pub fn from_sat_unprefixed_hex(s: &str) -> Result<Self, ParseAmountError> {
let amount = parse_int::hex_u64_unprefixed(s)
.map_err(|e| ParseAmountError(ParseAmountErrorInner::UnprefixedHex(e)))?;
- Ok(Self::from_sat(amount)
- .map_err(|e| ParseAmountError(ParseAmountErrorInner::OutOfRange(e)))?)
+ Self::from_sat(amount).map_err(|e| ParseAmountError(ParseAmountErrorInner::OutOfRange(e)))
}
/// Constructs a new object that implements [`fmt::Display`] in the given [`Denomination`].
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.