Have cfgs as part of the input to impl_unsafe_marker_for_simd (#207)

... so that the macro can correctly expand with `doc(cfg(...))` attributes under `feature = "nightly_docs"`.
This commit is contained in:
zachs18 2023-09-05 15:01:02 -05:00 committed by GitHub
parent d9b23e3518
commit b38d7d0e21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 118 additions and 101 deletions

View File

@ -79,10 +79,13 @@ macro_rules! transmute {
/// with relevant cargo features enabled. /// with relevant cargo features enabled.
#[allow(unused)] #[allow(unused)]
macro_rules! impl_unsafe_marker_for_simd { macro_rules! impl_unsafe_marker_for_simd {
(unsafe impl $trait:ident for $platform:ident :: {}) => {}; ($(#[cfg($cfg_predicate:meta)])? unsafe impl $trait:ident for $platform:ident :: {}) => {};
(unsafe impl $trait:ident for $platform:ident :: { $first_type:ident $(, $types:ident)* $(,)? }) => { ($(#[cfg($cfg_predicate:meta)])? unsafe impl $trait:ident for $platform:ident :: { $first_type:ident $(, $types:ident)* $(,)? }) => {
$( #[cfg($cfg_predicate)] )?
$( #[cfg_attr(feature = "nightly_docs", doc(cfg($cfg_predicate)))] )?
unsafe impl $trait for $platform::$first_type {} unsafe impl $trait for $platform::$first_type {}
impl_unsafe_marker_for_simd!(unsafe impl $trait for $platform::{ $( $types ),* }); $( #[cfg($cfg_predicate)] )? // To prevent recursion errors if nothing is going to be expanded anyway.
impl_unsafe_marker_for_simd!($( #[cfg($cfg_predicate)] )? unsafe impl $trait for $platform::{ $( $types ),* });
}; };
} }

View File

@ -54,13 +54,22 @@ unsafe impl Pod for f64 {}
unsafe impl<T: Pod> Pod for Wrapping<T> {} unsafe impl<T: Pod> Pod for Wrapping<T> {}
#[cfg(feature = "unsound_ptr_pod_impl")] #[cfg(feature = "unsound_ptr_pod_impl")]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "unsound_ptr_pod_impl")))] #[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "unsound_ptr_pod_impl"))
)]
unsafe impl<T: 'static> Pod for *mut T {} unsafe impl<T: 'static> Pod for *mut T {}
#[cfg(feature = "unsound_ptr_pod_impl")] #[cfg(feature = "unsound_ptr_pod_impl")]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "unsound_ptr_pod_impl")))] #[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "unsound_ptr_pod_impl"))
)]
unsafe impl<T: 'static> Pod for *const T {} unsafe impl<T: 'static> Pod for *const T {}
#[cfg(feature = "unsound_ptr_pod_impl")] #[cfg(feature = "unsound_ptr_pod_impl")]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "unsound_ptr_pod_impl")))] #[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "unsound_ptr_pod_impl"))
)]
unsafe impl<T: 'static> PodInOption for NonNull<T> {} unsafe impl<T: 'static> PodInOption for NonNull<T> {}
unsafe impl<T: ?Sized + 'static> Pod for PhantomData<T> {} unsafe impl<T: ?Sized + 'static> Pod for PhantomData<T> {}
@ -80,13 +89,13 @@ impl_unsafe_marker_for_array!(
512, 1024, 2048, 4096 512, 1024, 2048, 4096
); );
#[cfg(all(target_arch = "wasm32", feature = "wasm_simd"))]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "wasm32", feature = "wasm_simd"))]
unsafe impl Pod for wasm32::{v128} unsafe impl Pod for wasm32::{v128}
); );
#[cfg(all(target_arch = "aarch64", feature = "aarch64_simd"))]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "aarch64", feature = "aarch64_simd"))]
unsafe impl Pod for aarch64::{ unsafe impl Pod for aarch64::{
float32x2_t, float32x2x2_t, float32x2x3_t, float32x2x4_t, float32x4_t, float32x2_t, float32x2x2_t, float32x2x3_t, float32x2x4_t, float32x4_t,
float32x4x2_t, float32x4x3_t, float32x4x4_t, float64x1_t, float64x1x2_t, float32x4x2_t, float32x4x3_t, float32x4x4_t, float64x1_t, float64x1x2_t,
@ -111,16 +120,16 @@ impl_unsafe_marker_for_simd!(
} }
); );
#[cfg(target_arch = "x86")]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(target_arch = "x86")]
unsafe impl Pod for x86::{ unsafe impl Pod for x86::{
__m128i, __m128, __m128d, __m128i, __m128, __m128d,
__m256i, __m256, __m256d, __m256i, __m256, __m256d,
} }
); );
#[cfg(target_arch = "x86_64")]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(target_arch = "x86_64")]
unsafe impl Pod for x86_64::{ unsafe impl Pod for x86_64::{
__m128i, __m128, __m128d, __m128i, __m128, __m128d,
__m256i, __m256, __m256d, __m256i, __m256, __m256d,
@ -128,7 +137,10 @@ impl_unsafe_marker_for_simd!(
); );
#[cfg(feature = "nightly_portable_simd")] #[cfg(feature = "nightly_portable_simd")]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_portable_simd")))] #[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "nightly_portable_simd"))
)]
unsafe impl<T, const N: usize> Pod for core::simd::Simd<T, N> unsafe impl<T, const N: usize> Pod for core::simd::Simd<T, N>
where where
T: core::simd::SimdElement + Pod, T: core::simd::SimdElement + Pod,
@ -136,18 +148,16 @@ where
{ {
} }
#[cfg(all(target_arch = "x86", feature = "nightly_stdsimd"))]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_stdsimd")))]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "x86", feature = "nightly_stdsimd"))]
unsafe impl Pod for x86::{ unsafe impl Pod for x86::{
__m128bh, __m256bh, __m512, __m128bh, __m256bh, __m512,
__m512bh, __m512d, __m512i, __m512bh, __m512d, __m512i,
} }
); );
#[cfg(all(target_arch = "x86_64", feature = "nightly_stdsimd"))]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_stdsimd")))]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "x86_64", feature = "nightly_stdsimd"))]
unsafe impl Pod for x86_64::{ unsafe impl Pod for x86_64::{
__m128bh, __m256bh, __m512, __m128bh, __m256bh, __m512,
__m512bh, __m512d, __m512i, __m512bh, __m512d, __m512i,

View File

@ -19,8 +19,8 @@ use super::*;
/// ///
/// * `MaybeUninit<T>` was not available in 1.34.0, but is available under the /// * `MaybeUninit<T>` was not available in 1.34.0, but is available under the
/// `zeroable_maybe_uninit` feature flag. /// `zeroable_maybe_uninit` feature flag.
/// * `Atomic*` types require Rust 1.60.0 or later to work on certain platforms, but is available /// * `Atomic*` types require Rust 1.60.0 or later to work on certain platforms,
/// under the `zeroable_atomics` feature flag. /// but is available under the `zeroable_atomics` feature flag.
/// * `[T; N]` for arbitrary `N` requires the `min_const_generics` feature flag. /// * `[T; N]` for arbitrary `N` requires the `min_const_generics` feature flag.
pub unsafe trait Zeroable: Sized { pub unsafe trait Zeroable: Sized {
/// Calls [`zeroed`](core::mem::zeroed). /// Calls [`zeroed`](core::mem::zeroed).
@ -107,7 +107,10 @@ mod atomic_impls {
} }
#[cfg(feature = "zeroable_maybe_uninit")] #[cfg(feature = "zeroable_maybe_uninit")]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "zeroable_maybe_uninit")))] #[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "zeroable_maybe_uninit"))
)]
unsafe impl<T> Zeroable for core::mem::MaybeUninit<T> {} unsafe impl<T> Zeroable for core::mem::MaybeUninit<T> {}
unsafe impl<A: Zeroable> Zeroable for (A,) {} unsafe impl<A: Zeroable> Zeroable for (A,) {}
@ -166,13 +169,13 @@ impl_unsafe_marker_for_array!(
512, 1024, 2048, 4096 512, 1024, 2048, 4096
); );
#[cfg(all(target_arch = "wasm32", feature = "wasm_simd"))]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "wasm32", feature = "wasm_simd"))]
unsafe impl Zeroable for wasm32::{v128} unsafe impl Zeroable for wasm32::{v128}
); );
#[cfg(all(target_arch = "aarch64", feature = "aarch64_simd"))]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "aarch64", feature = "aarch64_simd"))]
unsafe impl Zeroable for aarch64::{ unsafe impl Zeroable for aarch64::{
float32x2_t, float32x2x2_t, float32x2x3_t, float32x2x4_t, float32x4_t, float32x2_t, float32x2x2_t, float32x2x3_t, float32x2x4_t, float32x4_t,
float32x4x2_t, float32x4x3_t, float32x4x4_t, float64x1_t, float64x1x2_t, float32x4x2_t, float32x4x3_t, float32x4x4_t, float64x1_t, float64x1x2_t,
@ -197,16 +200,16 @@ impl_unsafe_marker_for_simd!(
} }
); );
#[cfg(target_arch = "x86")]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(target_arch = "x86")]
unsafe impl Zeroable for x86::{ unsafe impl Zeroable for x86::{
__m128i, __m128, __m128d, __m128i, __m128, __m128d,
__m256i, __m256, __m256d, __m256i, __m256, __m256d,
} }
); );
#[cfg(target_arch = "x86_64")]
impl_unsafe_marker_for_simd!( impl_unsafe_marker_for_simd!(
#[cfg(target_arch = "x86_64")]
unsafe impl Zeroable for x86_64::{ unsafe impl Zeroable for x86_64::{
__m128i, __m128, __m128d, __m128i, __m128, __m128d,
__m256i, __m256, __m256d, __m256i, __m256, __m256d,
@ -214,7 +217,10 @@ impl_unsafe_marker_for_simd!(
); );
#[cfg(feature = "nightly_portable_simd")] #[cfg(feature = "nightly_portable_simd")]
#[cfg_attr(feature = "nightly_docs", doc(cfg(feature = "nightly_portable_simd")))] #[cfg_attr(
feature = "nightly_docs",
doc(cfg(feature = "nightly_portable_simd"))
)]
unsafe impl<T, const N: usize> Zeroable for core::simd::Simd<T, N> unsafe impl<T, const N: usize> Zeroable for core::simd::Simd<T, N>
where where
T: core::simd::SimdElement + Zeroable, T: core::simd::SimdElement + Zeroable,
@ -222,18 +228,16 @@ 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!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "x86", feature = "nightly_stdsimd"))]
unsafe impl Zeroable for x86::{ unsafe impl Zeroable for x86::{
__m128bh, __m256bh, __m512, __m128bh, __m256bh, __m512,
__m512bh, __m512d, __m512i, __m512bh, __m512d, __m512i,
} }
); );
#[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!( impl_unsafe_marker_for_simd!(
#[cfg(all(target_arch = "x86_64", feature = "nightly_stdsimd"))]
unsafe impl Zeroable for x86_64::{ unsafe impl Zeroable for x86_64::{
__m128bh, __m256bh, __m512, __m128bh, __m256bh, __m512,
__m512bh, __m512d, __m512i, __m512bh, __m512d, __m512i,