Skip to content

Commit ac90bb5

Browse files
authored
[doc] Use doc(cfg(...)) in more places (#599)
Use the `doc(cfg(...))` syntax in more places when generating documentation: - `impl<T> FromZeroes for Option<Box<T>>` - trait impls for simd types Release 0.7.26. Closes #597
1 parent 2182b96 commit ac90bb5

File tree

4 files changed

+66
-50
lines changed

4 files changed

+66
-50
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[package]
1616
edition = "2018"
1717
name = "zerocopy"
18-
version = "0.7.25"
18+
version = "0.7.26"
1919
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
2020
description = "Utilities for zero-copy parsing and serialization"
2121
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
@@ -49,7 +49,7 @@ simd-nightly = ["simd"]
4949
__internal_use_only_features_that_work_on_stable = ["alloc", "derive", "simd"]
5050

5151
[dependencies]
52-
zerocopy-derive = { version = "=0.7.25", path = "zerocopy-derive", optional = true }
52+
zerocopy-derive = { version = "=0.7.26", path = "zerocopy-derive", optional = true }
5353

5454
[dependencies.byteorder]
5555
version = "1.3"
@@ -60,7 +60,7 @@ optional = true
6060
# zerocopy-derive remain equal, even if the 'derive' feature isn't used.
6161
# See: https://github.com/matklad/macro-dep-test
6262
[target.'cfg(any())'.dependencies]
63-
zerocopy-derive = { version = "=0.7.25", path = "zerocopy-derive" }
63+
zerocopy-derive = { version = "=0.7.26", path = "zerocopy-derive" }
6464

6565
[dev-dependencies]
6666
assert_matches = "1.5"
@@ -75,6 +75,6 @@ testutil = { path = "testutil" }
7575
# CI test failures.
7676
trybuild = { version = "=1.0.85", features = ["diff"] }
7777
# In tests, unlike in production, zerocopy-derive is not optional
78-
zerocopy-derive = { version = "=0.7.25", path = "zerocopy-derive" }
78+
zerocopy-derive = { version = "=0.7.26", path = "zerocopy-derive" }
7979
# TODO(#381) Remove this dependency once we have our own layout gadgets.
8080
elain = "0.3.0"

src/lib.rs

Lines changed: 53 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,10 @@ safety_comment! {
19261926
/// TODO(#429), TODO(https://github.com/rust-lang/rust/pull/115333): Cite
19271927
/// the Stable docs once they're available.
19281928
#[cfg(feature = "alloc")]
1929-
unsafe_impl!(T => FromZeroes for Option<Box<T>>);
1929+
unsafe_impl!(
1930+
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
1931+
T => FromZeroes for Option<Box<T>>
1932+
);
19301933
unsafe_impl!(T => FromZeroes for Option<&'_ T>);
19311934
unsafe_impl!(T => FromZeroes for Option<&'_ mut T>);
19321935
unsafe_impl!(T => FromZeroes for Option<NonNull<T>>);
@@ -2149,6 +2152,7 @@ safety_comment! {
21492152
// [1] https://rust-lang.github.io/unsafe-code-guidelines/layout/packed-simd-vectors.html
21502153
// [2] https://github.com/rust-lang/unsafe-code-guidelines/issues/38
21512154
#[cfg(feature = "simd")]
2155+
#[cfg_attr(doc_cfg, doc(cfg(feature = "simd")))]
21522156
mod simd {
21532157
/// Defines a module which implements `FromZeroes`, `FromBytes`, and
21542158
/// `AsBytes` for a set of types from a module in `core::arch`.
@@ -2160,7 +2164,9 @@ mod simd {
21602164
// target/feature combinations don't emit any impls
21612165
// and thus don't use this macro.
21622166
macro_rules! simd_arch_mod {
2163-
($arch:ident, $mod:ident, $($typ:ident),*) => {
2167+
(#[cfg $cfg:tt] $arch:ident, $mod:ident, $($typ:ident),*) => {
2168+
#[cfg $cfg]
2169+
#[cfg_attr(doc_cfg, doc(cfg $cfg))]
21642170
mod $mod {
21652171
use core::arch::$arch::{$($typ),*};
21662172

@@ -2175,48 +2181,51 @@ mod simd {
21752181
};
21762182
}
21772183

2178-
#[cfg(target_arch = "x86")]
2179-
simd_arch_mod!(x86, x86, __m128, __m128d, __m128i, __m256, __m256d, __m256i);
2180-
#[cfg(all(feature = "simd-nightly", target_arch = "x86"))]
2181-
simd_arch_mod!(x86, x86_nightly, __m512bh, __m512, __m512d, __m512i);
2182-
#[cfg(target_arch = "x86_64")]
2183-
simd_arch_mod!(x86_64, x86_64, __m128, __m128d, __m128i, __m256, __m256d, __m256i);
2184-
#[cfg(all(feature = "simd-nightly", target_arch = "x86_64"))]
2185-
simd_arch_mod!(x86_64, x86_64_nightly, __m512bh, __m512, __m512d, __m512i);
2186-
#[cfg(target_arch = "wasm32")]
2187-
simd_arch_mod!(wasm32, wasm32, v128);
2188-
#[cfg(all(feature = "simd-nightly", target_arch = "powerpc"))]
2189-
simd_arch_mod!(
2190-
powerpc,
2191-
powerpc,
2192-
vector_bool_long,
2193-
vector_double,
2194-
vector_signed_long,
2195-
vector_unsigned_long
2196-
);
2197-
#[cfg(all(feature = "simd-nightly", target_arch = "powerpc64"))]
2198-
simd_arch_mod!(
2199-
powerpc64,
2200-
powerpc64,
2201-
vector_bool_long,
2202-
vector_double,
2203-
vector_signed_long,
2204-
vector_unsigned_long
2205-
);
2206-
#[cfg(target_arch = "aarch64")]
22072184
#[rustfmt::skip]
2208-
simd_arch_mod!(
2209-
aarch64, aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,
2210-
int8x8x3_t, int8x8x4_t, int8x16_t, int8x16x2_t, int8x16x3_t, int8x16x4_t, int16x4_t,
2211-
int16x8_t, int32x2_t, int32x4_t, int64x1_t, int64x2_t, poly8x8_t, poly8x8x2_t, poly8x8x3_t,
2212-
poly8x8x4_t, poly8x16_t, poly8x16x2_t, poly8x16x3_t, poly8x16x4_t, poly16x4_t, poly16x8_t,
2213-
poly64x1_t, poly64x2_t, uint8x8_t, uint8x8x2_t, uint8x8x3_t, uint8x8x4_t, uint8x16_t,
2214-
uint8x16x2_t, uint8x16x3_t, uint8x16x4_t, uint16x4_t, uint16x8_t, uint32x2_t, uint32x4_t,
2215-
uint64x1_t, uint64x2_t
2216-
);
2217-
#[cfg(all(feature = "simd-nightly", target_arch = "arm"))]
2218-
#[rustfmt::skip]
2219-
simd_arch_mod!(arm, arm, int8x4_t, uint8x4_t);
2185+
const _: () = {
2186+
simd_arch_mod!(
2187+
#[cfg(target_arch = "x86")]
2188+
x86, x86, __m128, __m128d, __m128i, __m256, __m256d, __m256i
2189+
);
2190+
simd_arch_mod!(
2191+
#[cfg(all(feature = "simd-nightly", target_arch = "x86"))]
2192+
x86, x86_nightly, __m512bh, __m512, __m512d, __m512i
2193+
);
2194+
simd_arch_mod!(
2195+
#[cfg(target_arch = "x86_64")]
2196+
x86_64, x86_64, __m128, __m128d, __m128i, __m256, __m256d, __m256i
2197+
);
2198+
simd_arch_mod!(
2199+
#[cfg(all(feature = "simd-nightly", target_arch = "x86_64"))]
2200+
x86_64, x86_64_nightly, __m512bh, __m512, __m512d, __m512i
2201+
);
2202+
simd_arch_mod!(
2203+
#[cfg(target_arch = "wasm32")]
2204+
wasm32, wasm32, v128
2205+
);
2206+
simd_arch_mod!(
2207+
#[cfg(all(feature = "simd-nightly", target_arch = "powerpc"))]
2208+
powerpc, powerpc, vector_bool_long, vector_double, vector_signed_long, vector_unsigned_long
2209+
);
2210+
simd_arch_mod!(
2211+
#[cfg(all(feature = "simd-nightly", target_arch = "powerpc64"))]
2212+
powerpc64, powerpc64, vector_bool_long, vector_double, vector_signed_long, vector_unsigned_long
2213+
);
2214+
simd_arch_mod!(
2215+
#[cfg(target_arch = "aarch64")]
2216+
aarch64, aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,
2217+
int8x8x3_t, int8x8x4_t, int8x16_t, int8x16x2_t, int8x16x3_t, int8x16x4_t, int16x4_t,
2218+
int16x8_t, int32x2_t, int32x4_t, int64x1_t, int64x2_t, poly8x8_t, poly8x8x2_t, poly8x8x3_t,
2219+
poly8x8x4_t, poly8x16_t, poly8x16x2_t, poly8x16x3_t, poly8x16x4_t, poly16x4_t, poly16x8_t,
2220+
poly64x1_t, poly64x2_t, uint8x8_t, uint8x8x2_t, uint8x8x3_t, uint8x8x4_t, uint8x16_t,
2221+
uint8x16x2_t, uint8x16x3_t, uint8x16x4_t, uint16x4_t, uint16x8_t, uint32x2_t, uint32x4_t,
2222+
uint64x1_t, uint64x2_t
2223+
);
2224+
simd_arch_mod!(
2225+
#[cfg(all(feature = "simd-nightly", target_arch = "arm"))]
2226+
arm, arm, int8x4_t, uint8x4_t
2227+
);
2228+
};
22202229
}
22212230

22222231
/// Safely transmutes a value of one type to a value of another type of the same
@@ -3658,6 +3667,7 @@ unsafe impl<'a> ByteSliceMut for &'a mut [u8] {}
36583667
unsafe impl<'a> ByteSliceMut for RefMut<'a, [u8]> {}
36593668

36603669
#[cfg(feature = "alloc")]
3670+
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
36613671
mod alloc_support {
36623672
use alloc::vec::Vec;
36633673

@@ -3875,7 +3885,6 @@ mod alloc_support {
38753885
}
38763886

38773887
#[cfg(feature = "alloc")]
3878-
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
38793888
#[doc(inline)]
38803889
pub use alloc_support::*;
38813890

src/macros.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ macro_rules! safety_comment {
3535
/// Unsafely implements trait(s) for a type.
3636
macro_rules! unsafe_impl {
3737
// Implement `$trait` for `$ty` with no bounds.
38-
($ty:ty: $trait:ty) => {
38+
($(#[$attr:meta])* $ty:ty: $trait:ty) => {
39+
$(#[$attr])*
3940
unsafe impl $trait for $ty { #[allow(clippy::missing_inline_in_public_items)] fn only_derive_is_allowed_to_implement_this_trait() {} }
4041
};
4142
// Implement all `$traits` for `$ty` with no bounds.
@@ -68,33 +69,39 @@ macro_rules! unsafe_impl {
6869
// The following arm has the same behavior with the exception of the lack of
6970
// support for a leading `const` parameter.
7071
(
72+
$(#[$attr:meta])*
7173
const $constname:ident : $constty:ident $(,)?
7274
$($tyvar:ident $(: $(? $optbound:ident $(+)?)* $($bound:ident $(+)?)* )?),*
7375
=> $trait:ident for $ty:ty
7476
) => {
7577
unsafe_impl!(
7678
@inner
79+
$(#[$attr])*
7780
@const $constname: $constty,
7881
$($tyvar $(: $(? $optbound +)* + $($bound +)*)?,)*
7982
=> $trait for $ty
8083
);
8184
};
8285
(
86+
$(#[$attr:meta])*
8387
$($tyvar:ident $(: $(? $optbound:ident $(+)?)* $($bound:ident $(+)?)* )?),*
8488
=> $trait:ident for $ty:ty
8589
) => {
8690
unsafe_impl!(
8791
@inner
92+
$(#[$attr])*
8893
$($tyvar $(: $(? $optbound +)* + $($bound +)*)?,)*
8994
=> $trait for $ty
9095
);
9196
};
9297
(
9398
@inner
99+
$(#[$attr:meta])*
94100
$(@const $constname:ident : $constty:ident,)*
95101
$($tyvar:ident $(: $(? $optbound:ident +)* + $($bound:ident +)* )?,)*
96102
=> $trait:ident for $ty:ty
97103
) => {
104+
$(#[$attr])*
98105
unsafe impl<$(const $constname: $constty,)* $($tyvar $(: $(? $optbound +)* $($bound +)*)?),*> $trait for $ty {
99106
#[allow(clippy::missing_inline_in_public_items)]
100107
fn only_derive_is_allowed_to_implement_this_trait() {}

zerocopy-derive/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[package]
1010
edition = "2018"
1111
name = "zerocopy-derive"
12-
version = "0.7.25"
12+
version = "0.7.26"
1313
authors = ["Joshua Liebow-Feeser <joshlf@google.com>"]
1414
description = "Custom derive for traits from the zerocopy crate"
1515
license = "BSD-2-Clause OR Apache-2.0 OR MIT"

0 commit comments

Comments
 (0)