From 6a7fb432260cca4a5eed552c2a0522046741e72a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Antinori?= Date: Tue, 30 Jun 2026 15:43:12 -0300 Subject: [PATCH 1/2] docs: link `Zeroable::zeroed` and `pin_init::zeroed` in documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modify the comments in the `pin_init::zeroed` and `Zeroable::zeroed` functions to cross-reference each other and make developers aware of both options. This also adapts the example code in `Zeroable::zeroed` doc comments to use that function. Link: https://lore.kernel.org/rust-for-linux/CANiq72m80vip+hz5RngvgH4VxU30amzS-ePr6KVKwKvhf3=Ycg@mail.gmail.com/T/#t Suggested-by: Miguel Ojeda Signed-off-by: Nicolás Antinori --- src/lib.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ef9f20b1..1f5005c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1539,10 +1539,13 @@ pub unsafe trait Zeroable { /// Whenever a type implements [`Zeroable`], this function should be preferred over /// [`core::mem::zeroed()`] or using `MaybeUninit::zeroed().assume_init()`. /// + /// As const traits are not yet stable, [`pin_init::zeroed()`] can be used instead + /// when initialization is required in a `const` context. + /// /// # Examples /// /// ``` - /// use pin_init::{Zeroable, zeroed}; + /// use pin_init::Zeroable; /// /// #[derive(Zeroable)] /// struct Point { @@ -1550,7 +1553,7 @@ pub unsafe trait Zeroable { /// y: u32, /// } /// - /// let point: Point = zeroed(); + /// let point: Point = Zeroable::zeroed(); /// assert_eq!(point.x, 0); /// assert_eq!(point.y, 0); /// ``` @@ -1582,6 +1585,9 @@ pub fn init_zeroed() -> impl Init { /// Whenever a type implements [`Zeroable`], this function should be preferred over /// [`core::mem::zeroed()`] or using `MaybeUninit::zeroed().assume_init()`. /// +/// While const traits remain unstable, this function serves as the `const` version of +/// [`Zeroable::zeroed()`]. +/// /// # Examples /// /// ``` From cd9092baada573d8539201c2c2cd945c4744f581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Antinori?= Date: Mon, 13 Jul 2026 11:39:08 -0300 Subject: [PATCH 2/2] mark `pin_init::zeroed` and `Zeroable::zeroed` as `#[inline]` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `pin_init::zeroed` function is a trivial wrapper around `unsafe { core::mem::zeroed() }`, whereas `Zeroable::zeroed` is a trivial wrapper around `pin_init::zeroed`. Mark them both as `#[inline]` to avoid generating unnecessary symbols for them. Signed-off-by: Nicolás Antinori --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 1f5005c1..f4ccb0e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1557,6 +1557,7 @@ pub unsafe trait Zeroable { /// assert_eq!(point.x, 0); /// assert_eq!(point.y, 0); /// ``` + #[inline] fn zeroed() -> Self where Self: Sized, @@ -1603,6 +1604,7 @@ pub fn init_zeroed() -> impl Init { /// assert_eq!(point.x, 0); /// assert_eq!(point.y, 0); /// ``` +#[inline] pub const fn zeroed() -> T { // SAFETY:By the type invariants of `Zeroable`, all zeroes is a valid bit pattern for `T`. unsafe { core::mem::zeroed() }