]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rust: pin-init: internal: init: simplify Zeroable safety check
authorBenno Lossin <lossin@kernel.org>
Fri, 16 Jan 2026 10:54:29 +0000 (11:54 +0100)
committerBenno Lossin <lossin@kernel.org>
Sat, 17 Jan 2026 09:51:43 +0000 (10:51 +0100)
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>
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Benno Lossin <lossin@kernel.org>
rust/pin-init/internal/src/init.rs

index ed2e1462e176a44a8ed47b6fab0020bd8b77e56d..42936f915a07ac57c7177f6e01c459c1dd5e5e1f 100644 (file)
@@ -414,17 +414,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()
                 })
             };
         },