Skip to content

Commit 9caa350

Browse files
committed
last docs changes and zeroable unsized pointer fixes
1 parent e881094 commit 9caa350

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

src/lib.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,16 @@
243243
//! [structurally pinned fields]:
244244
//! https://doc.rust-lang.org/std/pin/index.html#pinning-is-structural-for-field
245245
//! [stack]: crate::stack_pin_init
246-
//! [`Arc<T>`]: https://doc.rust-lang.org/stable/alloc/sync/struct.Arc.html
247-
//! [`Box<T>`]: https://doc.rust-lang.org/stable/alloc/boxed/struct.Box.html
246+
#![cfg_attr(
247+
kernel,
248+
doc = "[`Arc<T>`]: https://rust.docs.kernel.org/kernel/sync/struct.Arc.html"
249+
)]
250+
#![cfg_attr(
251+
kernel,
252+
doc = "[`Box<T>`]: https://rust.docs.kernel.org/kernel/alloc/kbox/struct.Box.html"
253+
)]
254+
#![cfg_attr(not(kernel), doc = "[`Arc<T>`]: alloc::alloc::sync::Arc")]
255+
#![cfg_attr(not(kernel), doc = "[`Box<T>`]: alloc::alloc::boxed::Box")]
248256
//! [`impl PinInit<Foo>`]: crate::PinInit
249257
//! [`impl PinInit<T, E>`]: crate::PinInit
250258
//! [`impl Init<T, E>`]: crate::Init
@@ -981,8 +989,16 @@ macro_rules! assert_pinned {
981989
/// - `slot` is not partially initialized.
982990
/// - while constructing the `T` at `slot` it upholds the pinning invariants of `T`.
983991
///
984-
/// [`Arc<T>`]: alloc::alloc::sync::Arc
985-
/// [`Box<T>`]: alloc::alloc::boxed::Box
992+
#[cfg_attr(
993+
kernel,
994+
doc = "[`Arc<T>`]: https://rust.docs.kernel.org/kernel/sync/struct.Arc.html"
995+
)]
996+
#[cfg_attr(
997+
kernel,
998+
doc = "[`Box<T>`]: https://rust.docs.kernel.org/kernel/alloc/kbox/struct.Box.html"
999+
)]
1000+
#[cfg_attr(not(kernel), doc = "[`Arc<T>`]: alloc::alloc::sync::Arc")]
1001+
#[cfg_attr(not(kernel), doc = "[`Box<T>`]: alloc::alloc::boxed::Box")]
9861002
#[must_use = "An initializer must be used in order to create its value."]
9871003
pub unsafe trait PinInit<T: ?Sized, E = Infallible>: Sized {
9881004
/// Initializes `slot`.
@@ -1072,8 +1088,16 @@ where
10721088
/// Contrary to its supertype [`PinInit<T, E>`] the caller is allowed to
10731089
/// move the pointee after initialization.
10741090
///
1075-
/// [`Arc<T>`]: alloc::alloc::sync::Arc
1076-
/// [`Box<T>`]: alloc::alloc::boxed::Box
1091+
#[cfg_attr(
1092+
kernel,
1093+
doc = "[`Arc<T>`]: https://rust.docs.kernel.org/kernel/sync/struct.Arc.html"
1094+
)]
1095+
#[cfg_attr(
1096+
kernel,
1097+
doc = "[`Box<T>`]: https://rust.docs.kernel.org/kernel/alloc/kbox/struct.Box.html"
1098+
)]
1099+
#[cfg_attr(not(kernel), doc = "[`Arc<T>`]: alloc::alloc::sync::Arc")]
1100+
#[cfg_attr(not(kernel), doc = "[`Box<T>`]: alloc::alloc::boxed::Box")]
10771101
#[must_use = "An initializer must be used in order to create its value."]
10781102
pub unsafe trait Init<T: ?Sized, E = Infallible>: PinInit<T, E> {
10791103
/// Initializes `slot`.
@@ -1422,16 +1446,13 @@ impl_zeroable! {
14221446
// SAFETY: `T: Zeroable` and `UnsafeCell` is `repr(transparent)`.
14231447
{<T: ?Sized + Zeroable>} UnsafeCell<T>,
14241448

1425-
// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
1449+
// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee:
1450+
// https://doc.rust-lang.org/stable/std/option/index.html#representation).
14261451
Option<NonZeroU8>, Option<NonZeroU16>, Option<NonZeroU32>, Option<NonZeroU64>,
14271452
Option<NonZeroU128>, Option<NonZeroUsize>,
14281453
Option<NonZeroI8>, Option<NonZeroI16>, Option<NonZeroI32>, Option<NonZeroI64>,
14291454
Option<NonZeroI128>, Option<NonZeroIsize>,
1430-
1431-
// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee).
1432-
//
1433-
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
1434-
{<T: ?Sized>} Option<NonNull<T>>,
1455+
{<T>} Option<NonNull<T>>,
14351456

14361457
// SAFETY: `null` pointer is valid.
14371458
//

0 commit comments

Comments
 (0)