Use doc_auto_cfg

We can build docs using feature markers by using `doc_auto_cfg` now, no
need to manually call the `doc` attribute.
This commit is contained in:
Tobin C. Harding 2023-05-03 12:06:25 +10:00
parent be2999ad58
commit b6d0c3bfcd
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
12 changed files with 4 additions and 54 deletions

View File

@ -12,9 +12,8 @@ keywords = [ "crypto", "ECDSA", "secp256k1", "libsecp256k1", "bitcoin" ]
readme = "README.md"
edition = "2018"
# Should make docs.rs show all functions, even those behind non-default features
[package.metadata.docs.rs]
features = [ "rand", "rand-std", "serde", "bitcoin_hashes", "recovery", "global-context" ]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[features]

View File

@ -15,9 +15,8 @@ build = "build.rs"
links = "rustsecp256k1_v0_8_1"
edition = "2018"
# Should make docs.rs show all functions, even those behind non-default features
[package.metadata.docs.rs]
features = [ "recovery", "lowmemory" ]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
[build-dependencies]

View File

@ -20,7 +20,7 @@
#![deny(non_upper_case_globals, non_camel_case_types, non_snake_case, unused_mut)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#[cfg(any(test, feature = "std"))]
extern crate core;

View File

@ -3,14 +3,12 @@ use core::mem::ManuallyDrop;
use core::ptr::NonNull;
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub use self::alloc_only::*;
use crate::ffi::types::{c_uint, c_void, AlignedType};
use crate::ffi::{self, CPtr};
use crate::{Error, Secp256k1};
#[cfg(all(feature = "global-context", feature = "std"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "global-context", feature = "std"))))]
/// Module implementing a singleton pattern for a global `Secp256k1` context.
pub mod global {
@ -114,7 +112,6 @@ mod private {
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
mod alloc_only {
use core::marker::PhantomData;
use core::ptr::NonNull;

View File

@ -168,7 +168,6 @@ unsafe extern "C" fn c_callback(
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl ::serde::Serialize for SharedSecret {
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if s.is_human_readable() {
@ -181,7 +180,6 @@ impl ::serde::Serialize for SharedSecret {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> ::serde::Deserialize<'de> for SharedSecret {
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
if d.is_human_readable() {

View File

@ -8,7 +8,6 @@ pub mod serialized_signature;
use core::{fmt, ptr, str};
#[cfg(feature = "recovery")]
#[cfg_attr(docsrs, doc(cfg(feature = "recovery")))]
pub use self::recovery::{RecoverableSignature, RecoveryId};
pub use self::serialized_signature::SerializedSignature;
use crate::ffi::CPtr;
@ -193,7 +192,6 @@ impl Signature {
/// The signature must be normalized or verification will fail (see [`Signature::normalize_s`]).
#[inline]
#[cfg(feature = "global-context")]
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
pub fn verify(&self, msg: &Message, pk: &PublicKey) -> Result<(), Error> {
SECP256K1.verify_ecdsa(msg, self, pk)
}
@ -214,7 +212,6 @@ impl From<ffi::Signature> for Signature {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl serde::Serialize for Signature {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if s.is_human_readable() {
@ -226,7 +223,6 @@ impl serde::Serialize for Signature {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> serde::Deserialize<'de> for Signature {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
if d.is_human_readable() {

View File

@ -126,7 +126,6 @@ impl RecoverableSignature {
/// verify-capable context.
#[inline]
#[cfg(feature = "global-context")]
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
pub fn recover(&self, msg: &Message) -> Result<key::PublicKey, Error> {
crate::SECP256K1.recover_ecdsa(msg, self)
}

View File

@ -198,7 +198,6 @@ impl SecretKey {
/// ```
#[inline]
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn new<R: rand::Rng + ?Sized>(rng: &mut R) -> SecretKey {
let mut data = crate::random_32_bytes(rng);
unsafe {
@ -286,7 +285,6 @@ impl SecretKey {
/// # }
/// ```
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
#[inline]
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
<H as hashes::Hash>::hash(data).into()
@ -355,7 +353,6 @@ impl SecretKey {
/// Constructs an ECDSA signature for `msg` using the global [`SECP256K1`] context.
#[inline]
#[cfg(feature = "global-context")]
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
pub fn sign_ecdsa(&self, msg: Message) -> ecdsa::Signature { SECP256K1.sign_ecdsa(&msg, self) }
/// Returns the [`KeyPair`] for this [`SecretKey`].
@ -393,7 +390,6 @@ impl<T: ThirtyTwoByteHash> From<T> for SecretKey {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl serde::Serialize for SecretKey {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if s.is_human_readable() {
@ -410,7 +406,6 @@ impl serde::Serialize for SecretKey {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> serde::Deserialize<'de> for SecretKey {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
if d.is_human_readable() {
@ -469,7 +464,6 @@ impl PublicKey {
/// Creates a new public key from a [`SecretKey`] and the global [`SECP256K1`] context.
#[inline]
#[cfg(feature = "global-context")]
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
pub fn from_secret_key_global(sk: &SecretKey) -> PublicKey {
PublicKey::from_secret_key(SECP256K1, sk)
}
@ -740,7 +734,6 @@ impl From<ffi::PublicKey> for PublicKey {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl serde::Serialize for PublicKey {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if s.is_human_readable() {
@ -757,7 +750,6 @@ impl serde::Serialize for PublicKey {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> serde::Deserialize<'de> for PublicKey {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<PublicKey, D::Error> {
if d.is_human_readable() {
@ -877,7 +869,6 @@ impl KeyPair {
/// [`Error::InvalidSecretKey`] if corresponding public key for the provided secret key is not even.
#[inline]
#[cfg(feature = "global-context")]
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
pub fn from_seckey_str_global(s: &str) -> Result<KeyPair, Error> {
KeyPair::from_seckey_str(SECP256K1, s)
}
@ -895,7 +886,6 @@ impl KeyPair {
/// ```
#[inline]
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn new<R: rand::Rng + ?Sized, C: Signing>(secp: &Secp256k1<C>, rng: &mut R) -> KeyPair {
let mut data = crate::random_32_bytes(rng);
unsafe {
@ -912,7 +902,6 @@ impl KeyPair {
/// Generates a new random secret key using the global [`SECP256K1`] context.
#[inline]
#[cfg(all(feature = "global-context", feature = "rand"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "global-context", feature = "rand"))))]
pub fn new_global<R: ::rand::Rng + ?Sized>(rng: &mut R) -> KeyPair {
KeyPair::new(SECP256K1, rng)
}
@ -989,7 +978,6 @@ impl KeyPair {
/// Constructs an schnorr signature for `msg` using the global [`SECP256K1`] context.
#[inline]
#[cfg(all(feature = "global-context", feature = "rand-std"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "global-context", feature = "rand-std"))))]
pub fn sign_schnorr(&self, msg: Message) -> schnorr::Signature {
SECP256K1.sign_schnorr(&msg, self)
}
@ -1044,7 +1032,6 @@ impl str::FromStr for KeyPair {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl serde::Serialize for KeyPair {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if s.is_human_readable() {
@ -1064,7 +1051,6 @@ impl serde::Serialize for KeyPair {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> serde::Deserialize<'de> for KeyPair {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
if d.is_human_readable() {
@ -1439,7 +1425,6 @@ impl fmt::Display for InvalidParityValue {
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for InvalidParityValue {}
impl From<InvalidParityValue> for Error {
@ -1448,7 +1433,6 @@ impl From<InvalidParityValue> for Error {
/// The parity is serialized as `u8` - `0` for even, `1` for odd.
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl serde::Serialize for Parity {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_u8(self.to_u8())
@ -1457,7 +1441,6 @@ impl serde::Serialize for Parity {
/// The parity is deserialized as `u8` - `0` for even, `1` for odd.
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> serde::Deserialize<'de> for Parity {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
struct Visitor;
@ -1516,7 +1499,6 @@ impl From<PublicKey> for XOnlyPublicKey {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl serde::Serialize for XOnlyPublicKey {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
if s.is_human_readable() {
@ -1532,7 +1514,6 @@ impl serde::Serialize for XOnlyPublicKey {
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> serde::Deserialize<'de> for XOnlyPublicKey {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
if d.is_human_readable() {

View File

@ -154,7 +154,7 @@
#![warn(missing_docs, missing_copy_implementations, missing_debug_implementations)]
#![cfg_attr(all(not(test), not(feature = "std")), no_std)]
// Experimental features we need.
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![cfg_attr(bench, feature(test))]
#[cfg(feature = "alloc")]
@ -184,17 +184,13 @@ use core::ptr::NonNull;
use core::{fmt, mem, str};
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
pub use bitcoin_hashes as hashes;
#[cfg(feature = "global-context")]
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
pub use context::global::SECP256K1;
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub use rand;
pub use secp256k1_sys as ffi;
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
pub use serde;
pub use crate::context::*;
@ -214,19 +210,16 @@ pub trait ThirtyTwoByteHash {
}
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl ThirtyTwoByteHash for hashes::sha256::Hash {
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
}
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl ThirtyTwoByteHash for hashes::sha256d::Hash {
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
}
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
impl<T: hashes::sha256t::Tag> ThirtyTwoByteHash for hashes::sha256t::Hash<T> {
fn into_32(self) -> [u8; 32] { self.to_byte_array() }
}
@ -275,7 +268,6 @@ impl Message {
/// # }
/// ```
#[cfg(feature = "bitcoin_hashes")]
#[cfg_attr(docsrs, doc(cfg(feature = "bitcoin-hashes")))]
pub fn from_hashed_data<H: ThirtyTwoByteHash + hashes::Hash>(data: &[u8]) -> Self {
<H as hashes::Hash>::hash(data).into()
}
@ -349,7 +341,6 @@ impl fmt::Display for Error {
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
@ -422,7 +413,6 @@ impl<C: Context> Secp256k1<C> {
/// Requires compilation with "rand" feature. See comment by Gregory Maxwell in
/// [libsecp256k1](https://github.com/bitcoin-core/secp256k1/commit/d2275795ff22a6f4738869f5528fbbb61738aa48).
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn randomize<R: rand::Rng + ?Sized>(&mut self, rng: &mut R) {
let mut seed = [0u8; 32];
rng.fill_bytes(&mut seed);
@ -453,7 +443,6 @@ impl<C: Signing> Secp256k1<C> {
/// [`PublicKey::from_secret_key`].
#[inline]
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn generate_keypair<R: rand::Rng + ?Sized>(
&self,
rng: &mut R,
@ -467,7 +456,6 @@ impl<C: Signing> Secp256k1<C> {
/// Generates a random keypair using the global [`SECP256K1`] context.
#[inline]
#[cfg(all(feature = "global-context", feature = "rand"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "global-context", feature = "rand"))))]
pub fn generate_keypair<R: rand::Rng + ?Sized>(rng: &mut R) -> (key::SecretKey, key::PublicKey) {
SECP256K1.generate_keypair(rng)
}

View File

@ -40,12 +40,10 @@ impl Scalar {
/// Generates a random scalar
#[cfg(feature = "rand-std")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))]
pub fn random() -> Self { Self::random_custom(rand::thread_rng()) }
/// Generates a random scalar using supplied RNG
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn random_custom<R: rand::Rng>(mut rng: R) -> Self {
let mut bytes = [0u8; 32];
loop {
@ -137,5 +135,4 @@ impl fmt::Display for OutOfRangeError {
}
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for OutOfRangeError {}

View File

@ -89,7 +89,6 @@ impl Signature {
/// Verifies a schnorr signature for `msg` using `pk` and the global [`SECP256K1`] context.
#[inline]
#[cfg(feature = "global-context")]
#[cfg_attr(docsrs, doc(cfg(feature = "global-context")))]
pub fn verify(&self, msg: &Message, pk: &XOnlyPublicKey) -> Result<(), Error> {
SECP256K1.verify_schnorr(self, msg, pk)
}
@ -122,7 +121,6 @@ impl<C: Signing> Secp256k1<C> {
/// Creates a schnorr signature internally using the [`rand::rngs::ThreadRng`] random number
/// generator to generate the auxiliary random data.
#[cfg(feature = "rand-std")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand-std")))]
pub fn sign_schnorr(&self, msg: &Message, keypair: &KeyPair) -> Signature {
self.sign_schnorr_with_rng(msg, keypair, &mut rand::thread_rng())
}
@ -145,7 +143,6 @@ impl<C: Signing> Secp256k1<C> {
/// Creates a schnorr signature using the given random number generator to
/// generate the auxiliary random data.
#[cfg(feature = "rand")]
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
pub fn sign_schnorr_with_rng<R: Rng + CryptoRng>(
&self,
msg: &Message,

View File

@ -24,7 +24,6 @@ macro_rules! impl_display_secret {
// Default hasher exists only in standard library and not alloc
($thing:ident) => {
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl core::fmt::Debug for $thing {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
use core::hash::Hasher;