Skip to content

Commit

Permalink
Use doc_auto_cfg (#883)
Browse files Browse the repository at this point in the history
Removes all manual `doc(cfg(...))` annotations, populating them
automatically instead using `feature(doc_auto_cfg)`.

As this feature is still unstable, it's still gated on the `docsrs` cfg
attributes.
  • Loading branch information
tarcieri authored Feb 26, 2023
1 parent 89f3caa commit a0b4200
Show file tree
Hide file tree
Showing 71 changed files with 31 additions and 291 deletions.
2 changes: 1 addition & 1 deletion base16ct/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
Expand Down
2 changes: 0 additions & 2 deletions base16ct/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn decode(src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], Error> {

/// Decode a lower Base16 (hex) string into a byte vector.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn decode_vec(input: impl AsRef<[u8]>) -> Result<Vec<u8>, Error> {
let mut output = vec![0u8; decoded_len(input.as_ref())?];
decode(input, &mut output)?;
Expand Down Expand Up @@ -41,7 +40,6 @@ pub fn encode_str<'a>(src: &[u8], dst: &'a mut [u8]) -> Result<&'a str, Error> {
/// # Panics
/// If `input` length is greater than `usize::MAX/2`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn encode_string(input: &[u8]) -> String {
let elen = encoded_len(input);
let mut dst = vec![0u8; elen];
Expand Down
1 change: 0 additions & 1 deletion base16ct/src/mixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn decode(src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], Error> {

/// Decode a mixed Base16 (hex) string into a byte vector.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn decode_vec(input: impl AsRef<[u8]>) -> Result<Vec<u8>, Error> {
let mut output = vec![0u8; decoded_len(input.as_ref())?];
decode(input, &mut output)?;
Expand Down
2 changes: 0 additions & 2 deletions base16ct/src/upper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub fn decode(src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], Error> {

/// Decode an upper Base16 (hex) string into a byte vector.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn decode_vec(input: impl AsRef<[u8]>) -> Result<Vec<u8>, Error> {
let mut output = vec![0u8; decoded_len(input.as_ref())?];
decode(input, &mut output)?;
Expand Down Expand Up @@ -41,7 +40,6 @@ pub fn encode_str<'a>(src: &[u8], dst: &'a mut [u8]) -> Result<&'a str, Error> {
/// # Panics
/// If `input` length is greater than `usize::MAX/2`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn encode_string(input: &[u8]) -> String {
let elen = encoded_len(input);
let mut dst = vec![0u8; elen];
Expand Down
4 changes: 0 additions & 4 deletions base32ct/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub trait Encoding: Alphabet {

/// Decode a Base32 string into a byte vector.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn decode_vec(input: &str) -> Result<Vec<u8>>;

/// Encode the input byte slice as Base32.
Expand All @@ -25,7 +24,6 @@ pub trait Encoding: Alphabet {

/// Encode input byte slice into a [`String`] containing Base32.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn encode_string(input: &[u8]) -> String;

/// Get the length of Base32 produced by encoding the given bytes.
Expand Down Expand Up @@ -129,7 +127,6 @@ impl<T: Alphabet> Encoding for T {
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn decode_vec(input: &str) -> Result<Vec<u8>> {
let mut output = vec![0u8; decoded_len(input.len())];
let len = Self::decode(input, &mut output)?.len();
Expand Down Expand Up @@ -208,7 +205,6 @@ impl<T: Alphabet> Encoding for T {
}

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn encode_string(input: &[u8]) -> String {
let elen = Self::encoded_len(input);
let mut dst = vec![0u8; elen];
Expand Down
2 changes: 1 addition & 1 deletion base32ct/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
// SOFTWARE.

#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
Expand Down
2 changes: 0 additions & 2 deletions base64ct/src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ impl<'i, E: Encoding> Decoder<'i, E> {
/// If successful, this function will return the total number of bytes
/// decoded into `buf`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn decode_to_end<'o>(&mut self, buf: &'o mut Vec<u8>) -> Result<&'o [u8], Error> {
let start_len = buf.len();
let remaining_len = self.remaining_len();
Expand Down Expand Up @@ -249,7 +248,6 @@ impl<'i, E: Encoding> Decoder<'i, E> {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'i, E: Encoding> io::Read for Decoder<'i, E> {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
if self.is_finished() {
Expand Down
1 change: 0 additions & 1 deletion base64ct/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ impl<'o, E: Encoding> Encoder<'o, E> {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'o, E: Encoding> io::Write for Encoder<'o, E> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.encode(buf)?;
Expand Down
2 changes: 0 additions & 2 deletions base64ct/src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub trait Encoding: Alphabet {

/// Decode a Base64 string into a byte vector.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn decode_vec(input: &str) -> Result<Vec<u8>, Error>;

/// Encode the input byte slice as Base64.
Expand All @@ -54,7 +53,6 @@ pub trait Encoding: Alphabet {
/// # Panics
/// If `input` length is greater than `usize::MAX/4`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn encode_string(input: &[u8]) -> String;

/// Get the length of Base64 produced by encoding the given bytes.
Expand Down
2 changes: 0 additions & 2 deletions base64ct/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ impl From<core::str::Utf8Error> for Error {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl From<Error> for std::io::Error {
fn from(err: Error) -> std::io::Error {
// TODO(tarcieri): better customize `ErrorKind`?
Expand All @@ -82,5 +81,4 @@ impl From<Error> for std::io::Error {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl std::error::Error for Error {}
2 changes: 1 addition & 1 deletion base64ct/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
Expand Down
2 changes: 1 addition & 1 deletion cmpv2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
Expand Down
2 changes: 1 addition & 1 deletion cms/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
Expand Down
3 changes: 1 addition & 2 deletions const-oid/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
Expand Down Expand Up @@ -32,7 +32,6 @@ mod error;
mod parser;

#[cfg(feature = "db")]
#[cfg_attr(docsrs, doc(cfg(feature = "db")))]
pub mod db;

pub use crate::{
Expand Down
2 changes: 1 addition & 1 deletion crmf/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![no_std]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
Expand Down
2 changes: 0 additions & 2 deletions der/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub use self::{
};

#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub use self::{
any::Any,
bit_string::BitString,
Expand All @@ -62,5 +61,4 @@ pub use self::{
};

#[cfg(feature = "oid")]
#[cfg_attr(docsrs, doc(cfg(feature = "oid")))]
pub use const_oid::ObjectIdentifier;
1 change: 0 additions & 1 deletion der/src/asn1/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ mod allocating {
///
/// This type provides the same functionality as [`AnyRef`] but owns the
/// backing data.
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct Any {
Expand Down
1 change: 0 additions & 1 deletion der/src/asn1/bit_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ mod allocating {
///
/// This type provides the same functionality as [`BitStringRef`] but owns the
/// backing data.
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct BitString {
/// Number of unused bits in the final octet.
Expand Down
18 changes: 0 additions & 18 deletions der/src/asn1/generalized_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ impl GeneralizedTime {

/// Instantiate from [`SystemTime`].
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn from_system_time(time: SystemTime) -> Result<Self> {
DateTime::try_from(time)
.map(Into::into)
Expand All @@ -70,7 +69,6 @@ impl GeneralizedTime {

/// Convert to [`SystemTime`].
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn to_system_time(&self) -> SystemTime {
self.0.to_system_time()
}
Expand Down Expand Up @@ -190,15 +188,13 @@ impl FixedTag for DateTime {
impl OrdIsValueOrd for DateTime {}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'a> DecodeValue<'a> for SystemTime {
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
Ok(GeneralizedTime::decode_value(reader, header)?.into())
}
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl EncodeValue for SystemTime {
fn value_len(&self) -> Result<Length> {
GeneralizedTime::try_from(self)?.value_len()
Expand All @@ -210,23 +206,20 @@ impl EncodeValue for SystemTime {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl From<GeneralizedTime> for SystemTime {
fn from(time: GeneralizedTime) -> SystemTime {
time.to_system_time()
}
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl From<&GeneralizedTime> for SystemTime {
fn from(time: &GeneralizedTime) -> SystemTime {
time.to_system_time()
}
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl TryFrom<SystemTime> for GeneralizedTime {
type Error = Error;

Expand All @@ -236,7 +229,6 @@ impl TryFrom<SystemTime> for GeneralizedTime {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl TryFrom<&SystemTime> for GeneralizedTime {
type Error = Error;

Expand All @@ -246,7 +238,6 @@ impl TryFrom<&SystemTime> for GeneralizedTime {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl<'a> TryFrom<AnyRef<'a>> for SystemTime {
type Error = Error;

Expand All @@ -256,25 +247,21 @@ impl<'a> TryFrom<AnyRef<'a>> for SystemTime {
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl FixedTag for SystemTime {
const TAG: Tag = Tag::GeneralizedTime;
}

#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
impl OrdIsValueOrd for SystemTime {}

#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
impl<'a> DecodeValue<'a> for PrimitiveDateTime {
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
GeneralizedTime::decode_value(reader, header)?.try_into()
}
}

#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
impl EncodeValue for PrimitiveDateTime {
fn value_len(&self) -> Result<Length> {
GeneralizedTime::try_from(self)?.value_len()
Expand All @@ -286,17 +273,14 @@ impl EncodeValue for PrimitiveDateTime {
}

#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
impl FixedTag for PrimitiveDateTime {
const TAG: Tag = Tag::GeneralizedTime;
}

#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
impl OrdIsValueOrd for PrimitiveDateTime {}

#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
impl TryFrom<PrimitiveDateTime> for GeneralizedTime {
type Error = Error;

Expand All @@ -306,7 +290,6 @@ impl TryFrom<PrimitiveDateTime> for GeneralizedTime {
}

#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
impl TryFrom<&PrimitiveDateTime> for GeneralizedTime {
type Error = Error;

Expand All @@ -316,7 +299,6 @@ impl TryFrom<&PrimitiveDateTime> for GeneralizedTime {
}

#[cfg(feature = "time")]
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
impl TryFrom<GeneralizedTime> for PrimitiveDateTime {
type Error = Error;

Expand Down
1 change: 0 additions & 1 deletion der/src/asn1/octet_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ mod allocating {
///
/// This type provides the same functionality as [`OctetStringRef`] but owns
/// the backing data.
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub struct OctetString {
/// Bitstring represented as a slice of bytes.
Expand Down
3 changes: 0 additions & 3 deletions der/src/asn1/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use crate::{

use super::integer::uint::strip_leading_zeroes;

#[cfg_attr(docsrs, doc(cfg(feature = "real")))]
impl<'a> DecodeValue<'a> for f64 {
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self> {
let bytes = BytesRef::decode_value(reader, header)?.as_slice();
Expand Down Expand Up @@ -84,7 +83,6 @@ impl<'a> DecodeValue<'a> for f64 {
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "real")))]
impl EncodeValue for f64 {
fn value_len(&self) -> Result<Length> {
if self.is_sign_positive() && (*self) < f64::MIN_POSITIVE {
Expand Down Expand Up @@ -194,7 +192,6 @@ impl EncodeValue for f64 {
}
}

#[cfg_attr(docsrs, doc(cfg(feature = "real")))]
impl FixedTag for f64 {
const TAG: Tag = Tag::Real;
}
Expand Down
Loading

0 comments on commit a0b4200

Please sign in to comment.