From: "Gary Guo" <gary@garyguo.net>
To: "Tamir Duberstein" <tamird@gmail.com>, "Gary Guo" <gary@garyguo.net>
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Alice Ryhl" <aliceryhl@google.com>,
"Trevor Gross" <tmgross@umich.edu>,
"Danilo Krummrich" <dakr@kernel.org>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] rust: macros: support `#[cfg]` properly in `#[vtable]` macro.
Date: Tue, 13 Jan 2026 14:09:46 +0000 [thread overview]
Message-ID: <DFNIS32ARBRQ.1842L2438YTMB@garyguo.net> (raw)
In-Reply-To: <CAJ-ks9m4bCoQbrHeO14wXdFyMhkWf=SRzqkxY=gk9tpB594cCQ@mail.gmail.com>
On Tue Jan 13, 2026 at 1:39 PM GMT, Tamir Duberstein wrote:
> On Tue, Jan 13, 2026 at 8:11 AM Gary Guo <gary@kernel.org> wrote:
>>
>> From: Gary Guo <gary@garyguo.net>
>>
>> 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>
>> ---
>> rust/macros/helpers.rs | 6 ++++++
>> rust/macros/vtable.rs | 13 ++++---------
>> 2 files changed, 10 insertions(+), 9 deletions(-)
>>
>> diff --git a/rust/macros/helpers.rs b/rust/macros/helpers.rs
>> index adfa60d8f42d8..11117b4c95d25 100644
>> --- a/rust/macros/helpers.rs
>> +++ b/rust/macros/helpers.rs
>> @@ -7,6 +7,7 @@
>> Parse,
>> ParseStream, //
>> },
>> + Attribute,
>> Error,
>> LitStr,
>> Result, //
>> @@ -53,3 +54,8 @@ pub(crate) fn file() -> String {
>> proc_macro::Span::call_site().file()
>> }
>> }
>> +
>> +/// Obtain all `#[cfg]` attributes.
>> +pub(crate) fn gather_cfg_attrs(attr: &[Attribute]) -> impl Iterator<Item = Attribute> + '_ {
>> + attr.iter().filter(|a| a.path().is_ident("cfg")).cloned()
>> +}
>
> There's also no need to clone; `ToTokens::to_tokens` takes `&self`.
>
> https://docs.rs/quote/latest/quote/trait.ToTokens.html#tymethod.to_tokens
Indeed. In that case I feel like the line is short enough and we can just inline
these and skip the helper function?
Best,
Gary
next prev parent reply other threads:[~2026-01-13 14:09 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260112170919.1888584-1-gary@kernel.org>
2026-01-12 17:07 ` [PATCH v3 01/12] rust: pin-init: internal: remove proc-macro[2] and quote workarounds Gary Guo
2026-01-12 17:07 ` [PATCH v3 02/12] rust: macros: use `quote!` from vendored crate Gary Guo
2026-01-19 7:09 ` David Gow
2026-01-12 17:07 ` [PATCH v3 03/12] rust: macros: convert `#[vtable]` macro to use `syn` Gary Guo
2026-01-17 19:25 ` Benno Lossin
2026-01-12 17:07 ` [PATCH v3 04/12] rust: macros: use `syn` to parse `module!` macro Gary Guo
2026-01-17 20:12 ` Benno Lossin
2026-01-12 17:07 ` [PATCH v3 05/12] rust: macros: use `quote!` for " Gary Guo
2026-01-12 17:07 ` [PATCH v3 06/12] rust: macros: convert `#[export]` to use `syn` Gary Guo
2026-01-12 17:07 ` [PATCH v3 07/12] rust: macros: convert `concat_idents!` " Gary Guo
2026-01-12 17:07 ` [PATCH v3 08/12] rust: macros: convert `#[kunit_tests]` macro " Gary Guo
2026-01-17 20:09 ` Benno Lossin
2026-01-19 7:10 ` David Gow
2026-01-12 17:07 ` [PATCH v3 09/12] rust: macros: allow arbitrary types to be used in `module!` macro Gary Guo
2026-01-12 17:07 ` [PATCH v3 10/12] rust: macros: rearrange `#[doc(hidden)]` " Gary Guo
2026-01-12 17:07 ` [PATCH v3 11/12] rust: kunit: use `pin_init::zeroed` instead of custom null value Gary Guo
2026-01-19 7:10 ` David Gow
2026-01-12 17:07 ` [PATCH v3 12/12] rust: macros: support `#[cfg]` properly in `#[vtable]` macro Gary Guo
2026-01-12 17:48 ` Tamir Duberstein
2026-01-13 13:11 ` [PATCH] " Gary Guo
2026-01-13 13:39 ` Tamir Duberstein
2026-01-13 14:09 ` Gary Guo [this message]
2026-01-13 14:23 ` Tamir Duberstein
2026-01-13 17:05 ` [PATCH v2] " Gary Guo
2026-01-17 20:09 ` Benno Lossin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DFNIS32ARBRQ.1842L2438YTMB@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@gmail.com \
--cc=tmgross@umich.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®