From a6007cf555e5946bcbfafe93a6468c329078acd8 Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Mon, 31 Mar 2025 22:17:33 +0200 Subject: [PATCH 1/2] alloc: restrict `impl ZeroableOption` for `Box` to `T: Sized` Similar to what was done for `Zeroable>` in commit 9caa3507c926 ("last docs changes and zeroable unsized pointer fixes"), the latest Rust documentation [1] says it guarantees that `transmute::<_, Option>([0u8; size_of::()])` is sound and produces `Option::::None` only in some cases. In particular, it says: `Box` (specifically, only `Box`) when `U: Sized` Thus restrict the `impl` to `Sized`, and use similar wording as in that commit too. Link: https://doc.rust-lang.org/stable/std/option/index.html#representation [1] Signed-off-by: Miguel Ojeda --- src/alloc.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/alloc.rs b/src/alloc.rs index e16baa3b..5017f574 100644 --- a/src/alloc.rs +++ b/src/alloc.rs @@ -17,11 +17,9 @@ use crate::{ pub extern crate alloc; -// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee). -// -// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant and there -// is no problem with a VTABLE pointer being null. -unsafe impl ZeroableOption for Box {} +// SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee: +// ). +unsafe impl ZeroableOption for Box {} /// Smart pointer that can initialize memory in-place. pub trait InPlaceInit: Sized { From dd230d61bf0538281072fbff4bb71efc58f3420c Mon Sep 17 00:00:00 2001 From: Miguel Ojeda Date: Tue, 1 Apr 2025 21:56:27 +0200 Subject: [PATCH 2/2] Use Markdown autolinks in Rust comments It allows, for instance, kitty to pick it up as links properly [1]. Suggested-by: Benno Lossin Link: https://github.com/Rust-for-Linux/pin-init/pull/32#discussion_r2023103712 [1] Signed-off-by: Miguel Ojeda --- examples/pthread_mutex.rs | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/pthread_mutex.rs b/examples/pthread_mutex.rs index 9164298c..5ac22f18 100644 --- a/examples/pthread_mutex.rs +++ b/examples/pthread_mutex.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT -// inspired by https://github.com/nbdd0121/pin-init/blob/trunk/examples/pthread_mutex.rs +// inspired by #![allow(clippy::undocumented_unsafe_blocks)] #![cfg_attr(feature = "alloc", feature(allocator_api))] #[cfg(not(windows))] diff --git a/src/lib.rs b/src/lib.rs index 05c44514..0806c689 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1447,7 +1447,7 @@ impl_zeroable! { {} UnsafeCell, // SAFETY: All zeros is equivalent to `None` (option layout optimization guarantee: - // https://doc.rust-lang.org/stable/std/option/index.html#representation). + // ). Option, Option, Option, Option, Option, Option, Option, Option, Option, Option,