]> git.ipfire.org Git - thirdparty/linux.git/commit
rust: macros: support `#[cfg]` properly in `#[vtable]` macro.
authorGary Guo <gary@garyguo.net>
Tue, 13 Jan 2026 17:05:21 +0000 (17:05 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Wed, 28 Jan 2026 12:44:17 +0000 (13:44 +0100)
commit779f6e3e1cef07cb0c1241d483ed364e522bd280
treead94f222d67567427984a0424af98078cc60e73d
parentbe97f3c82021239476ce32cddde32948c597753e
rust: macros: support `#[cfg]` properly in `#[vtable]` macro.

Currently, we generate `HAS_` constants as long as the definition exists in
the source, regardless if it is cfg-ed out or not.

Currently, uses of `#[cfg]` present in both trait and impl, so it is not a
problem; however if only the impl side uses `#[cfg]` then `HAS_` constants
will incorrectly be true while it shouldnt't.

With `syn` support, we can now implement `#[cfg]` handling properly by
propagating the `#[cfg]` attributes to the constants.

Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://patch.msgid.link/20260113170529.2240744-1-gary@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
rust/macros/helpers.rs
rust/macros/vtable.rs