linux/rust/pin-init/internal/src
Gary Guo d2f3092279 rust: pin_init: internal: use loop {} to produce never value
In the `init!`/`pin_init!` macros, we rely on a trick that assigns never
(`!`) values to all mentioned fields in never-executed code to let the
compiler check that all fields have been initialized.

Currently we use `::core::panic!()` to produce this value, but before Rust
1.91.0, it creates outlined `panic_cold_explicit` functions which do not
get removed by the optimizer, thus leaving dead code behind in the binary.
This has been fixed by [1], which lands in Rust 1.91.0+, higher than the
kernel minimum version 1.85.0.

This causes ~200 dead `panic_cold_explicit` instances being included in the
binary, with ~90 of them from nova-core's usage of pin-init.

Work around the issue by using `loop {}` which creates the never value
without macro expansion or function call at all. All instances of
`panic_cold_explicit` outside libcore are removed by this change in my
kernel build.

Link: https://github.com/rust-lang/rust/pull/145304 [1]
Link: https://patch.msgid.link/20260508152950.833635-1-gary@kernel.org
Signed-off-by: Gary Guo <gary@garyguo.net>
2026-05-29 21:58:36 +01:00
..
diagnostics.rs rust: pin-init: internal: turn PhantomPinned error into warnings 2026-05-10 22:58:34 +01:00
init.rs rust: pin_init: internal: use loop {} to produce never value 2026-05-29 21:58:36 +01:00
lib.rs rust: pin-init: bump minimum Rust version to 1.82 2026-05-10 22:58:33 +01:00
pin_data.rs rust: pin-init: internal: suppress non_snake_case lint in #[pin_data] 2026-05-29 21:34:53 +01:00
pinned_drop.rs rust: pin-init: rewrite the #[pinned_drop] attribute macro using syn 2026-01-17 10:51:42 +01:00
zeroable.rs rust: pin-init: internal: adjust license identifier of zeroable.rs 2026-05-10 22:58:34 +01:00