diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..9d8a446 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,4 @@ +[alias] + +# The list of features should be the same as the one under `[package.metadata.docs.rs]` +nightly_docs = "doc --no-deps -F nightly_docs,derive,extern_crate_alloc,extern_crate_std,zeroable_maybe_uninit,zeroable_atomics,min_const_generics,wasm_simd,must_cast" diff --git a/Cargo.toml b/Cargo.toml index e429457..0a82e8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,12 +30,16 @@ unsound_ptr_pod_impl = [] nightly_portable_simd = [] nightly_stdsimd = [] +# Improved documentation using the nightly toolchain +nightly_docs = [] + [dependencies] bytemuck_derive = { version = "1.4", path = "derive", optional = true } [package.metadata.docs.rs] # Note(Lokathor): Don't use all-features or it would use `unsound_ptr_pod_impl` too. features = [ + "nightly_docs", "derive", "extern_crate_alloc", "extern_crate_std", diff --git a/src/anybitpattern.rs b/src/anybitpattern.rs index c35a9a7..a759738 100644 --- a/src/anybitpattern.rs +++ b/src/anybitpattern.rs @@ -56,5 +56,6 @@ pub unsafe trait AnyBitPattern: unsafe impl AnyBitPattern for T {} #[cfg(feature = "zeroable_maybe_uninit")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "zeroable_maybe_uninit")))] unsafe impl AnyBitPattern for core::mem::MaybeUninit where T: AnyBitPattern {} diff --git a/src/checked.rs b/src/checked.rs index 68f72a9..722c31d 100644 --- a/src/checked.rs +++ b/src/checked.rs @@ -224,6 +224,7 @@ impl core::fmt::Display for CheckedCastError { } } #[cfg(feature = "extern_crate_std")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "extern_crate_std")))] impl std::error::Error for CheckedCastError {} impl From for CheckedCastError { diff --git a/src/lib.rs b/src/lib.rs index c49a3ba..a51ed8a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,7 @@ #![warn(missing_docs)] #![allow(clippy::match_like_matches_macro)] #![allow(clippy::uninlined_format_args)] +#![cfg_attr(feature = "nightly_docs", feature(doc_cfg))] #![cfg_attr(feature = "nightly_portable_simd", feature(portable_simd))] #![cfg_attr(feature = "nightly_stdsimd", feature(stdsimd))] @@ -91,6 +92,7 @@ extern crate std; #[cfg(feature = "extern_crate_alloc")] extern crate alloc; #[cfg(feature = "extern_crate_alloc")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "extern_crate_alloc")))] pub mod allocation; #[cfg(feature = "extern_crate_alloc")] pub use allocation::*; @@ -116,6 +118,7 @@ pub use pod_in_option::*; #[cfg(feature = "must_cast")] mod must; #[cfg(feature = "must_cast")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "must_cast")))] pub use must::*; mod no_uninit; @@ -131,6 +134,7 @@ mod transparent; pub use transparent::*; #[cfg(feature = "derive")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "derive")))] pub use bytemuck_derive::{ AnyBitPattern, ByteEq, ByteHash, CheckedBitPattern, Contiguous, NoUninit, Pod, TransparentWrapper, Zeroable, @@ -165,6 +169,7 @@ impl core::fmt::Display for PodCastError { } } #[cfg(feature = "extern_crate_std")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "extern_crate_std")))] impl std::error::Error for PodCastError {} /// Re-interprets `&T` as `&[u8]`. diff --git a/src/pod.rs b/src/pod.rs index a98def8..d72b8e5 100644 --- a/src/pod.rs +++ b/src/pod.rs @@ -54,10 +54,13 @@ unsafe impl Pod for f64 {} unsafe impl Pod for Wrapping {} #[cfg(feature = "unsound_ptr_pod_impl")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "unsound_ptr_pod_impl")))] unsafe impl Pod for *mut T {} #[cfg(feature = "unsound_ptr_pod_impl")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "unsound_ptr_pod_impl")))] unsafe impl Pod for *const T {} #[cfg(feature = "unsound_ptr_pod_impl")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "unsound_ptr_pod_impl")))] unsafe impl PodInOption for NonNull {} unsafe impl Pod for PhantomData {} @@ -67,6 +70,7 @@ unsafe impl Pod for ManuallyDrop {} // Note(Lokathor): MaybeUninit can NEVER be Pod. #[cfg(feature = "min_const_generics")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "min_const_generics")))] unsafe impl Pod for [T; N] where T: Pod {} #[cfg(not(feature = "min_const_generics"))] @@ -124,6 +128,7 @@ impl_unsafe_marker_for_simd!( ); #[cfg(feature = "nightly_portable_simd")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_portable_simd")))] unsafe impl Pod for core::simd::Simd where T: core::simd::SimdElement + Pod, @@ -132,6 +137,7 @@ where } #[cfg(all(target_arch = "x86", feature = "nightly_stdsimd"))] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_stdsimd")))] impl_unsafe_marker_for_simd!( unsafe impl Pod for x86::{ __m128bh, __m256bh, __m512, @@ -140,6 +146,7 @@ impl_unsafe_marker_for_simd!( ); #[cfg(all(target_arch = "x86_64", feature = "nightly_stdsimd"))] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_stdsimd")))] impl_unsafe_marker_for_simd!( unsafe impl Pod for x86_64::{ __m128bh, __m256bh, __m512, diff --git a/src/zeroable.rs b/src/zeroable.rs index d10fb1a..9078cf6 100644 --- a/src/zeroable.rs +++ b/src/zeroable.rs @@ -71,6 +71,7 @@ unsafe impl Zeroable for core::cell::UnsafeCell {} unsafe impl Zeroable for core::cell::Cell {} #[cfg(feature = "zeroable_atomics")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "zeroable_atomics")))] mod atomic_impls { use super::Zeroable; @@ -106,6 +107,7 @@ mod atomic_impls { } #[cfg(feature = "zeroable_maybe_uninit")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "zeroable_maybe_uninit")))] unsafe impl Zeroable for core::mem::MaybeUninit {} unsafe impl Zeroable for (A,) {} @@ -154,6 +156,7 @@ unsafe impl< } #[cfg(feature = "min_const_generics")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "min_const_generics")))] unsafe impl Zeroable for [T; N] where T: Zeroable {} #[cfg(not(feature = "min_const_generics"))] @@ -211,6 +214,7 @@ impl_unsafe_marker_for_simd!( ); #[cfg(feature = "nightly_portable_simd")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_portable_simd")))] unsafe impl Zeroable for core::simd::Simd where T: core::simd::SimdElement + Zeroable, @@ -219,6 +223,7 @@ where } #[cfg(all(target_arch = "x86", feature = "nightly_stdsimd"))] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_std_simd")))] impl_unsafe_marker_for_simd!( unsafe impl Zeroable for x86::{ __m128bh, __m256bh, __m512, @@ -227,6 +232,7 @@ impl_unsafe_marker_for_simd!( ); #[cfg(all(target_arch = "x86_64", feature = "nightly_stdsimd"))] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_std_simd")))] impl_unsafe_marker_for_simd!( unsafe impl Zeroable for x86_64::{ __m128bh, __m256bh, __m512, diff --git a/src/zeroable_in_option.rs b/src/zeroable_in_option.rs index b60beb1..c4cf158 100644 --- a/src/zeroable_in_option.rs +++ b/src/zeroable_in_option.rs @@ -31,4 +31,5 @@ unsafe impl ZeroableInOption for &'_ T {} unsafe impl ZeroableInOption for &'_ mut T {} #[cfg(feature = "extern_crate_alloc")] +#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "extern_crate_alloc")))] unsafe impl ZeroableInOption for alloc::boxed::Box {}