bitcoin: Split cfg(all(...)) into stacked attributes
What changed, and why it matters
This commit is a code-style refactor. It replaces single-line Rust conditional annotations like #[cfg(all(A, B))] with stacked separate lines like #[cfg(A)] #[cfg(B)]. The behavior is identical; no security issue is introduced or fixed.
No security action required. Treat as a normal maintenance/style change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff rewrites cfg predicates from #[cfg(all(…))] to multiple stacked #[cfg(…)] attributes. In Rust, stacked cfg attributes are logically ANDed, so the compiled conditional inclusion is unchanged. The change affects doc tests, unit tests, imports, and one integration test file, but does not alter runtime logic, APIs, or cryptographic behavior.
Changed components
bitcoin/src/address/mod.rsbitcoin/src/blockdata/transaction.rsbitcoin/src/consensus/encode.rsbitcoin/src/consensus_validation.rsbitcoin/src/crypto/key.rsbitcoin/src/lib.rsbitcoin/src/psbt/mod.rsbitcoin/src/sign_message.rsbitcoin/tests/psbt-sign-taproot.rsInspect captured patch +61 / −28
diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs
index 76125e05..97d9259b 100644
--- a/bitcoin/src/address/mod.rs
+++ b/bitcoin/src/address/mod.rs
@@ -9,7 +9,9 @@
//! ### Creating a new address from a randomly-generated key pair.
//!
//! ```rust
-//! #[cfg(all(feature = "rand", feature = "std"))] {
+//! #[cfg(feature = "rand")]
+//! #[cfg(feature = "std")]
+//! {
//! use bitcoin::secp256k1::rand;
//! use bitcoin::{Address, Network, PublicKey};
//!
diff --git a/bitcoin/src/blockdata/transaction.rs b/bitcoin/src/blockdata/transaction.rs
index 50d73807..97a8cf77 100644
--- a/bitcoin/src/blockdata/transaction.rs
+++ b/bitcoin/src/blockdata/transaction.rs
@@ -1650,7 +1650,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "std", feature = "bitcoinconsensus"))]
+ #[cfg(feature = "bitcoinconsensus")]
+ #[cfg(feature = "std")]
fn transaction_verify() {
use std::collections::HashMap;
diff --git a/bitcoin/src/consensus/encode.rs b/bitcoin/src/consensus/encode.rs
index 1d1ffb03..c16435a1 100644
--- a/bitcoin/src/consensus/encode.rs
+++ b/bitcoin/src/consensus/encode.rs
@@ -1096,7 +1096,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn serialization_round_trips() {
use secp256k1::rand::{self, Rng};
diff --git a/bitcoin/src/consensus_validation.rs b/bitcoin/src/consensus_validation.rs
index e3d02d9f..9ac9e804 100644
--- a/bitcoin/src/consensus_validation.rs
+++ b/bitcoin/src/consensus_validation.rs
@@ -223,7 +223,8 @@ impl fmt::Display for BitcoinconsensusError {
}
}
-#[cfg(all(feature = "std", feature = "bitcoinconsensus"))]
+#[cfg(feature = "bitcoinconsensus")]
+#[cfg(feature = "std")]
impl std::error::Error for BitcoinconsensusError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
diff --git a/bitcoin/src/crypto/key.rs b/bitcoin/src/crypto/key.rs
index 13b4ed63..f09d1c36 100644
--- a/bitcoin/src/crypto/key.rs
+++ b/bitcoin/src/crypto/key.rs
@@ -35,7 +35,8 @@ pub use encapsulate::{
CompressedPublicKey, Keypair, PrivateKey, PublicKey, SerializedXOnlyPublicKey, TweakedKeypair,
TweakedPublicKey, XOnlyPublicKey,
};
-#[cfg(all(feature = "rand", feature = "std"))]
+#[cfg(feature = "rand")]
+#[cfg(feature = "std")]
pub use secp256k1::rand;
/// Encapsulation module to provide a clear barrier for construction/destruction of types.
@@ -213,7 +214,9 @@ mod encapsulate {
/// # Examples
///
/// ```
- /// # #[cfg(all(feature = "rand", feature = "std"))] {
+ /// # #[cfg(feature = "rand")]
+ /// # #[cfg(feature = "std")]
+ /// # {
/// # use bitcoin::key::{Keypair, TweakedKeypair, TweakedPublicKey};
/// # let keypair = TweakedKeypair::dangerous_assume_tweaked(Keypair::generate());
/// // There are various conversion methods available to get a tweaked pubkey from a tweaked keypair.
@@ -395,14 +398,17 @@ impl Keypair {
/// # Examples
///
/// ```
- /// # #[cfg(all(feature = "rand", feature = "std"))] {
+ /// # #[cfg(feature = "rand")]
+ /// # #[cfg(feature = "std")]
+ /// # {
/// use bitcoin::Keypair;
///
/// let keypair = Keypair::generate();
/// # }
/// ```
#[inline]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
pub fn generate() -> Self {
let kp = secp256k1::Keypair::new(&mut rand::rng());
Self::from_secp(kp)
@@ -450,7 +456,8 @@ impl Keypair {
{
secp256k1::schnorr::sign_no_aux_rand(msg, self.as_inner())
}
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
{
secp256k1::schnorr::sign(msg, self.as_inner())
}
@@ -985,7 +992,8 @@ impl From<&CompressedPublicKey> for WPubkeyHash {
impl PrivateKey {
/// Constructs a new compressed ECDSA private key using the secp256k1 algorithm and
/// a secure random number generator.
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
pub fn generate() -> Self {
let secret_key = secp256k1::SecretKey::new(&mut rand::rng());
Self::from_secp(secret_key)
@@ -2172,7 +2180,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn public_key_constructors() {
let kp = Keypair::generate();
@@ -2289,7 +2298,8 @@ mod tests {
#[test]
fn keypair_from_str_roundtrip() {
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
let keypair = Keypair::generate();
#[cfg(not(all(feature = "rand", feature = "std")))]
let keypair = {
@@ -2308,7 +2318,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn keypair_secp_roundtrip() {
let bitcoin_key = Keypair::generate();
let secp_key =
@@ -2317,7 +2328,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn public_key_secp_roundtrip() {
let bitcoin_key = Keypair::generate().to_public_key();
let secp_key =
@@ -2335,7 +2347,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn xonly_secp_roundtrip() {
let bitcoin_key = Keypair::generate().to_x_only_public_key();
let secp_key =
@@ -2344,7 +2357,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn private_key_secp_roundtrip() {
let bitcoin_key = PrivateKey::generate();
let secp_key =
diff --git a/bitcoin/src/lib.rs b/bitcoin/src/lib.rs
index a2ded73e..58cb908d 100644
--- a/bitcoin/src/lib.rs
+++ b/bitcoin/src/lib.rs
@@ -198,7 +198,8 @@ mod prelude {
#[cfg(not(feature = "std"))]
pub use alloc::{string::{String, ToString}, vec::Vec, boxed::Box, borrow::{Borrow, BorrowMut, Cow, ToOwned}, slice, rc};
- #[cfg(all(not(feature = "std"), target_has_atomic = "ptr"))]
+ #[cfg(target_has_atomic = "ptr")]
+ #[cfg(not(feature = "std"))]
pub use alloc::sync;
#[cfg(feature = "std")]
diff --git a/bitcoin/src/psbt/mod.rs b/bitcoin/src/psbt/mod.rs
index b9f065f9..5bd9a526 100644
--- a/bitcoin/src/psbt/mod.rs
+++ b/bitcoin/src/psbt/mod.rs
@@ -1301,7 +1301,8 @@ mod tests {
use hashes::{hash160, ripemd160, sha256};
use hex_unstable::hex;
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
use {
crate::bip32::Fingerprint, crate::locktime, crate::script::ScriptPubKeyBufExt as _,
crate::witness_version::WitnessVersion, crate::WitnessProgram, secp256k1::SecretKey,
@@ -1312,7 +1313,8 @@ mod tests {
use crate::locktime::absolute;
use crate::network::NetworkKind;
use crate::psbt::serialize::{Deserialize, Serialize};
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
use crate::script::ScriptBufExt as _;
use crate::script::{RedeemScriptBuf, ScriptPubKeyBuf, ScriptSigBuf, WitnessScriptBuf};
use crate::transaction::{self, OutPoint, TxIn};
@@ -2353,7 +2355,8 @@ mod tests {
));
}
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn gen_keys() -> (PrivateKey, PublicKey) {
use secp256k1::rand;
@@ -2365,7 +2368,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn get_key_btree_map() {
let (priv_key, pk) = gen_keys();
@@ -2377,7 +2381,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn pubkey_map_get_key_negates_odd_parity_keys() {
use crate::psbt::{GetKey, KeyRequest};
@@ -2623,7 +2628,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn hashmap_can_sign_taproot() {
let (priv_key, pk) = gen_keys();
let internal_key: XOnlyPublicKey = pk.into();
@@ -2656,7 +2662,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn xonly_hashmap_can_sign_taproot() {
let (priv_key, pk) = gen_keys();
let internal_key: XOnlyPublicKey = pk.into();
@@ -2689,7 +2696,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "rand", feature = "std"))]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "std")]
fn sign_psbt() {
let unsigned_tx = Transaction {
version: transaction::Version::TWO,
diff --git a/bitcoin/src/sign_message.rs b/bitcoin/src/sign_message.rs
index ab2265fa..ad2786e9 100644
--- a/bitcoin/src/sign_message.rs
+++ b/bitcoin/src/sign_message.rs
@@ -232,7 +232,10 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "secp-recovery", feature = "base64", feature = "rand", feature = "std"))]
+ #[cfg(feature = "base64")]
+ #[cfg(feature = "rand")]
+ #[cfg(feature = "secp-recovery")]
+ #[cfg(feature = "std")]
fn message_signature() {
use crate::{Address, AddressType, CompressedPublicKey, Network, NetworkKind, PrivateKey};
@@ -274,7 +277,8 @@ mod tests {
}
#[test]
- #[cfg(all(feature = "secp-recovery", feature = "base64"))]
+ #[cfg(feature = "base64")]
+ #[cfg(feature = "secp-recovery")]
fn incorrect_message_signature() {
use base64::prelude::{Engine as _, BASE64_STANDARD};
diff --git a/bitcoin/tests/psbt-sign-taproot.rs b/bitcoin/tests/psbt-sign-taproot.rs
index cc72fce1..27964556 100644
--- a/bitcoin/tests/psbt-sign-taproot.rs
+++ b/bitcoin/tests/psbt-sign-taproot.rs
@@ -1,6 +1,7 @@
//! This test is excluded when the `rand` feature is enabled because Schnorr signatures use
//! auxiliary randomness, making them non-deterministic and incompatible with hardcoded test vectors.
-#![cfg(all(feature = "std", not(feature = "rand")))]
+#![cfg(feature = "std")]
+#![cfg(not(feature = "rand"))]
use std::collections::BTreeMap;
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.