[PATCH v3 14/15] rust: pin-init: internal: init: simplify Zeroable safety check

Benno Lossin posted 15 patches 3 weeks, 4 days ago
There is a newer version of this series
[PATCH v3 14/15] rust: pin-init: internal: init: simplify Zeroable safety check
Posted by Benno Lossin 3 weeks, 4 days ago
The `Zeroable` type check uses a small dance with a raw pointer to aid
type inference. It turns out that this is not necessary and type
inference is powerful enough to resolve any ambiguity. Thus remove it.

Suggested-by: Gary Guo <gary@garyguo.net>
Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
Signed-off-by: Benno Lossin <lossin@kernel.org>
---
Changes in v3: none
Changes in v2: added this patch
---
 rust/pin-init/internal/src/init.rs | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/rust/pin-init/internal/src/init.rs b/rust/pin-init/internal/src/init.rs
index 523741e62bd7..1b43e8847aa8 100644
--- a/rust/pin-init/internal/src/init.rs
+++ b/rust/pin-init/internal/src/init.rs
@@ -415,17 +415,12 @@ fn make_field_check(
             #[allow(unreachable_code, clippy::diverging_sub_expression, unused_assignments)]
             // SAFETY: this code is never executed.
             let _ = || unsafe {
-                let mut zeroed = ::core::mem::zeroed();
-                // We have to use type inference here to make zeroed have the correct type. This
-                // does not get executed, so it has no effect.
-                ::core::ptr::write(slot, zeroed);
-                zeroed = ::core::mem::zeroed();
                 ::core::ptr::write(slot, #path {
                     #(
                         #(#field_attrs)*
                         #field_name: ::core::panic!(),
                     )*
-                    ..zeroed
+                    ..::core::mem::zeroed()
                 })
             };
         },
-- 
2.52.0
Re: [PATCH v3 14/15] rust: pin-init: internal: init: simplify Zeroable safety check
Posted by Gary Guo 3 weeks, 4 days ago
On Wed Jan 14, 2026 at 6:18 PM GMT, Benno Lossin wrote:
> The `Zeroable` type check uses a small dance with a raw pointer to aid
> type inference. It turns out that this is not necessary and type
> inference is powerful enough to resolve any ambiguity. Thus remove it.
> 
> Suggested-by: Gary Guo <gary@garyguo.net>
> Tested-by: Andreas Hindborg <a.hindborg@kernel.org>
> Signed-off-by: Benno Lossin <lossin@kernel.org>

Reviewed-by: Gary Guo <gary@garyguo.net>

> ---
> Changes in v3: none
> Changes in v2: added this patch
> ---
>  rust/pin-init/internal/src/init.rs | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)