units: Split cfg(all(...)) into stacked attributes
What changed, and why it matters
This commit is a purely stylistic cleanup in the Rust Bitcoin library. It changes how the code tells the compiler which optional features must be enabled for certain pieces of code to compile, switching from combined conditions like `#[cfg(all(feature = "std", feature = "encoding"))]` to stacked single conditions like `#[cfg(feature = "std")]` followed by `#[cfg(feature = "encoding")]`. In Rust, these two forms mean the same thing, so this does not change behavior, fix a bug, or address a security issue.
No action required. This is a non-functional style refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff refactors #[cfg(all(...))] and #[cfg(not(...))]/#[cfg(...)] attribute combinations into stacked #[cfg(...)] attributes across six files in the units crate. Stacked #[cfg] attributes are logically ANDed by the Rust compiler, making them semantically equivalent to #[cfg(all(...))]. No logic, feature gates, or public APIs are changed. There is no security-relevant modification.
Changed components
units/src/amount/error.rsunits/src/amount/serde.rsunits/src/block.rsunits/src/locktime/absolute/error.rsunits/src/sequence.rsunits/src/time.rsInspect captured patch +27 / −14
diff --git a/units/src/amount/error.rs b/units/src/amount/error.rs
index 96830c24..b0d8fc00 100644
--- a/units/src/amount/error.rs
+++ b/units/src/amount/error.rs
@@ -459,7 +459,8 @@ impl fmt::Display for AmountDecoderError {
}
}
-#[cfg(all(feature = "std", feature = "encoding"))]
+#[cfg(feature = "encoding")]
+#[cfg(feature = "std")]
impl std::error::Error for AmountDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
use AmountDecoderErrorInner as E;
diff --git a/units/src/amount/serde.rs b/units/src/amount/serde.rs
index f8b0f4db..4e7ea1fb 100644
--- a/units/src/amount/serde.rs
+++ b/units/src/amount/serde.rs
@@ -46,8 +46,8 @@ impl fmt::Display for DisplayFullError {
}
}
-#[cfg(not(feature = "std"))]
#[cfg(feature = "alloc")]
+#[cfg(not(feature = "std"))]
impl fmt::Display for DisplayFullError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fmt::Display::fmt(&self.0, f) }
}
diff --git a/units/src/block.rs b/units/src/block.rs
index 7aee6320..b4f28a87 100644
--- a/units/src/block.rs
+++ b/units/src/block.rs
@@ -662,7 +662,8 @@ pub mod error {
}
}
- #[cfg(all(feature = "std", feature = "encoding"))]
+ #[cfg(feature = "encoding")]
+ #[cfg(feature = "std")]
impl std::error::Error for BlockHeightDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
diff --git a/units/src/locktime/absolute/error.rs b/units/src/locktime/absolute/error.rs
index 8fe6d581..bccb263e 100644
--- a/units/src/locktime/absolute/error.rs
+++ b/units/src/locktime/absolute/error.rs
@@ -29,7 +29,8 @@ impl fmt::Display for LockTimeDecoderError {
}
}
-#[cfg(all(feature = "std", feature = "encoding"))]
+#[cfg(feature = "encoding")]
+#[cfg(feature = "std")]
impl std::error::Error for LockTimeDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
@@ -330,7 +331,8 @@ mod tests {
#[cfg(feature = "std")]
use std::error::Error;
- #[cfg(all(feature = "encoding", feature = "alloc"))]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "encoding")]
use encoding::{Decodable as _, Decoder as _};
#[cfg(feature = "alloc")]
diff --git a/units/src/sequence.rs b/units/src/sequence.rs
index 0007a8e4..f8cfe3c5 100644
--- a/units/src/sequence.rs
+++ b/units/src/sequence.rs
@@ -342,7 +342,8 @@ pub mod error {
}
}
- #[cfg(all(feature = "std", feature = "encoding"))]
+ #[cfg(feature = "encoding")]
+ #[cfg(feature = "std")]
impl std::error::Error for SequenceDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
@@ -394,12 +395,15 @@ impl<'a> Arbitrary<'a> for Sequence {
mod tests {
#[cfg(feature = "alloc")]
use alloc::format;
- #[cfg(all(feature = "encoding", feature = "alloc"))]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "encoding")]
use alloc::string::ToString;
- #[cfg(all(feature = "encoding", feature = "std"))]
+ #[cfg(feature = "encoding")]
+ #[cfg(feature = "std")]
use std::error::Error;
- #[cfg(all(feature = "encoding", feature = "alloc"))]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "encoding")]
use encoding::UnexpectedEofError;
#[cfg(feature = "encoding")]
use encoding::{Decodable as _, Decoder as _};
@@ -509,7 +513,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "encoding", feature = "alloc"))]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "encoding")]
fn sequence_decoding_error() {
let bytes = [0xff, 0xff, 0xff]; // 3 bytes is an EOF error
diff --git a/units/src/time.rs b/units/src/time.rs
index a3fa5f92..52ad9217 100644
--- a/units/src/time.rs
+++ b/units/src/time.rs
@@ -200,7 +200,8 @@ pub mod error {
}
}
- #[cfg(all(feature = "std", feature = "encoding"))]
+ #[cfg(feature = "encoding")]
+ #[cfg(feature = "std")]
impl std::error::Error for BlockTimeDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
@@ -219,12 +220,14 @@ impl<'a> Arbitrary<'a> for BlockTime {
mod tests {
#[cfg(feature = "alloc")]
use alloc::string::ToString;
- #[cfg(all(feature = "encoding", feature = "std"))]
+ #[cfg(feature = "encoding")]
+ #[cfg(feature = "std")]
use std::error::Error;
#[cfg(feature = "encoding")]
use encoding::Decoder as _;
- #[cfg(all(feature = "encoding", feature = "alloc"))]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "encoding")]
use encoding::UnexpectedEofError;
use super::*;
@@ -248,7 +251,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "encoding", feature = "alloc"))]
+ #[cfg(feature = "alloc")]
+ #[cfg(feature = "encoding")]
fn block_time_decoding_error() {
let bytes = [0xb0, 0x52, 0x39]; // 3 bytes is an EOF error
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.