All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]`
@ 2026-06-11 19:05 Gary Guo
  2026-06-11 23:01 ` Alice Ryhl
  2026-06-12  4:40 ` Alexandre Courbot
  0 siblings, 2 replies; 3+ messages in thread
From: Gary Guo @ 2026-06-11 19:05 UTC (permalink / raw)
  To: Alexandre Courbot, Yury Norov, Miguel Ojeda, Boqun Feng, Gary Guo,
	Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl,
	Trevor Gross, Danilo Krummrich
  Cc: rust-for-linux, linux-kernel

From: Gary Guo <gary@garyguo.net>

A `Debug` impl is for debugging and is normally not used, and therefore
should ideally not be code-generated unless used. However, Rust has no way
of knowing if a dependent crate is going to use the trait impl or not, so
unless it is marked as `#[inline]`, it will be code-generated in the
defining crate (as it is not generic).

Mark the impl generated by bitfield macro `#[inline]`, so they do not stay
in the binary unless used.

This reduces nova-core.o .text by 17% (from 151922 bytes to 125676 bytes).

Signed-off-by: Gary Guo <gary@garyguo.net>
---
 rust/kernel/bitfield.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/rust/kernel/bitfield.rs b/rust/kernel/bitfield.rs
index 554a5a2ff0ab..35ede53f2b8e 100644
--- a/rust/kernel/bitfield.rs
+++ b/rust/kernel/bitfield.rs
@@ -535,6 +535,7 @@ const fn [<__with_ $field>](
     // `Debug` implementation.
     (@debug $name:ident { $($field:ident;)* }) => {
         impl ::kernel::fmt::Debug for $name {
+            #[inline]
             fn fmt(&self, f: &mut ::kernel::fmt::Formatter<'_>) -> ::kernel::fmt::Result {
                 f.debug_struct(stringify!($name))
                     .field("<raw>", &::kernel::prelude::fmt!("{:#x}", self.inner))

base-commit: 7f07865bda5f5770d2f7927bc76cb2b4acd46074
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-12  4:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-11 19:05 [PATCH] rust: bitfield: mark `Debug` impl as `#[inline]` Gary Guo
2026-06-11 23:01 ` Alice Ryhl
2026-06-12  4:40 ` Alexandre Courbot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.