Merge rust-bitcoin/rust-bitcoin#4055: hashes: Only enable hex/std, and hex/alloc when hex is

7c12d92bc3 Only enable hex/std, alloc when hex is (Jamil Lambert, PhD)
11770cac1c Add hashes to io dev-depencies and require hex (Jamil Lambert, PhD)
e7c6564d38 Add missing hex feature gate (Jamil Lambert, PhD)

Pull request description:

  `hex/std` and `hex/alloc` should only be included if optional dependency `hex` is enabled.  A bunch of tests that need `hex` relied on an `alloc` feature gate to ensure `hex/alloc` was enabled.

  Add feature gates to the tests that require `hex`.

  Add `?` so `hex/alloc` or `hex/std` are only included if the optional feature `hex` is enabled.

  Audit rest of crates `Cargo.toml` files: no other cases found.

  Close #4035

ACKs for top commit:
  Kixunil:
    ACK 7c12d92bc3
  apoelstra:
    ACK 7c12d92bc3011e1305238f0f5d3b155a01875814; successfully ran local tests; Played with cargo a bit; `cargo tree` seems to confirm that you can mix dev and non-dev dependencies like this.

Tree-SHA512: bd752d3c074dd8c93b09aa318d98ccb761b2f9baa2797566dd1d5f486349a92fbcd05787ddeb53d1f05ef0b29fbf559152f6373674fbec01e1251e74ad61e61f
This commit is contained in:
merge-script 2025-02-15 19:57:38 +00:00
commit 3fb5275e16
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
14 changed files with 22 additions and 2 deletions

View File

@ -15,8 +15,8 @@ exclude = ["tests", "contrib"]
[features]
default = ["std"]
std = ["alloc", "hex/std"]
alloc = ["hex/alloc"]
std = ["alloc", "hex?/std"]
alloc = ["hex?/alloc"]
serde = ["dep:serde", "hex"]
# Smaller (but slower) implementation of sha256, sha512 and ripemd160
small-hash = []

View File

@ -95,6 +95,7 @@ mod tests {
}
#[cfg(bench)]
#[cfg(feature = "hex")]
mod benches {
use test::Bencher;

View File

@ -47,6 +47,7 @@ impl crate::HashEngine for HashEngine {
mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

View File

@ -107,6 +107,7 @@ where
#[cfg(test)]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
mod tests {
use hex::prelude::{DisplayHex, FromHex};

View File

@ -326,6 +326,7 @@ mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn newtype_fmt_roundtrip() {
use alloc::format;

View File

@ -1,5 +1,6 @@
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

View File

@ -1,5 +1,6 @@
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

View File

@ -5,6 +5,7 @@ use crate::{sha256, HashEngine};
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;
@ -70,6 +71,7 @@ fn test() {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn fmt_roundtrips() {
use alloc::format;

View File

@ -45,6 +45,7 @@ mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;
@ -98,6 +99,7 @@ mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn fmt_roundtrips() {
use alloc::format;

View File

@ -182,10 +182,12 @@ mod tests {
// The digest created by sha256 hashing `&[0]` starting with `TEST_MIDSTATE`.
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
const HASH_ZERO_BACKWARD: &str =
"29589d5122ec666ab5b4695070b6debc63881a4f85d88d93ddc90078038213ed";
// And the same thing, forward.
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
const HASH_ZERO_FORWARD: &str =
"ed1382037800c9dd938dd8854f1a8863bcdeb6705069b4b56a66ec22519d5829";
@ -198,10 +200,12 @@ mod tests {
// We support manually implementing `Tag` and creating a tagged hash from it.
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
pub type TestHash = sha256t::Hash<TestHashTag>;
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn manually_created_sha256t_hash_type() {
use alloc::string::ToString;

View File

@ -41,6 +41,7 @@ impl crate::HashEngine for HashEngine {
mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

View File

@ -1,5 +1,6 @@
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

View File

@ -51,6 +51,7 @@ impl crate::HashEngine for HashEngine {
mod tests {
#[test]
#[cfg(feature = "alloc")]
#[cfg(feature = "hex")]
fn test() {
use alloc::string::ToString;

View File

@ -23,6 +23,9 @@ internals = { package = "bitcoin-internals", version = "0.4.0" }
hashes = { package = "bitcoin_hashes", version = "0.16.0", default-features = false, optional = true }
[dev-dependencies]
hashes = { package = "bitcoin_hashes", version = "0.16.0", default-features = false, features = ["hex"] }
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]