Skip to content

Conversation

@tcharding
Copy link
Member

Example relies on rand-std not plain rand dependency.

I do not understand why the following command passes without this patch
applied

cargo test --no-default-features --features=std,rand,bitcoin_hashes

But if we put the same code in a standalone binary it fails as expected?

Since the running of this test is unusual and it is primarily meant as
an entry point example to the library, remove the mention of "alloc"
feature and just depend upon "std".

Fixes: #395

Example relies on `rand-std` not plain `rand` dependency.

I do not understand why the following command passes without this patch
applied

```
cargo test --no-default-features --features=std,rand,bitcoin_hashes
```

But if we put the same code in a standalone binary it fails as expected?

Since the running of this test is _unusual_ and it is primarily meant as
an entry point example to the library, remove the mention of "alloc"
feature and just depend upon "std".
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 3c9dd2f

If I understand the issue correctly, this example would not have have worked with alloc anyway, since it depends on std implicitly through rand-std.

Edit: forgot "not"

@apoelstra apoelstra merged commit b8615e2 into rust-bitcoin:master Feb 9, 2022
@tcharding
Copy link
Member Author

Its the "rand" vs "rand-std" thing that this PR really fixes.

I may have confused things by removing "alloc" at the same time, my bad. I dropped the "alloc" because I'm wondering if all the recent feature gates I changed were incorrect, it seems confusing to not have "std" enabled but have "rand-std" enabled, even if technically this all works. Why would anyone ever do this. But changing them all again seems like code churn, not sure what to do?

@apoelstra
Copy link
Member

@tcharding lol, I think the code churn would be ok. We haven't actually done a release yet.

My bad as well, for reading your changes and not noticing that rand-std and alloc is a nearly-incoherent combination ... although as you say, it does technically work.

For readers: we are talking about the recent changes in #386 commit 6, which replaces a bunch of rand feature gates with rand-std, but then doesn't change the simultaneous any(alloc, std) feature gate to std. This only affects documentation example code.

@tcharding tcharding deleted the fix-rand-dep branch February 11, 2022 08:36
chain-forgexcr45 added a commit to chain-forgexcr45/rust-secp256k1 that referenced this pull request Sep 28, 2025
3c9dd2fb326b4ffe9680885d1de79904499a4043 Fix example dependency list (Tobin Harding)

Pull request description:

  Example relies on `rand-std` not plain `rand` dependency.

  I do not understand why the following command passes without this patch
  applied

  ```
  cargo test --no-default-features --features=std,rand,bitcoin_hashes
  ```

  But if we put the same code in a standalone binary it fails as expected?

  Since the running of this test is _unusual_ and it is primarily meant as
  an entry point example to the library, remove the mention of "alloc"
  feature and just depend upon "std".

  Fixes: #395

ACKs for top commit:
  apoelstra:
    ACK 3c9dd2fb326b4ffe9680885d1de79904499a4043

Tree-SHA512: 8e7ec7ac846e2916c29b74c7485650e5242ae1141c12c69b50d74efdfee71c11a52cd454231d2a7cdd6f8f683d3ba4369f9bf898a6b9351dc92c2a4e2bd626cd
william2332-limf added a commit to william2332-limf/rust-secp256k1 that referenced this pull request Oct 2, 2025
3c9dd2fb326b4ffe9680885d1de79904499a4043 Fix example dependency list (Tobin Harding)

Pull request description:

  Example relies on `rand-std` not plain `rand` dependency.

  I do not understand why the following command passes without this patch
  applied

  ```
  cargo test --no-default-features --features=std,rand,bitcoin_hashes
  ```

  But if we put the same code in a standalone binary it fails as expected?

  Since the running of this test is _unusual_ and it is primarily meant as
  an entry point example to the library, remove the mention of "alloc"
  feature and just depend upon "std".

  Fixes: #395

ACKs for top commit:
  apoelstra:
    ACK 3c9dd2fb326b4ffe9680885d1de79904499a4043

Tree-SHA512: 8e7ec7ac846e2916c29b74c7485650e5242ae1141c12c69b50d74efdfee71c11a52cd454231d2a7cdd6f8f683d3ba4369f9bf898a6b9351dc92c2a4e2bd626cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Is documentation outdated?

2 participants