From: Gary Guo <gary@garyguo.net>
To: "Miguel Ojeda" <ojeda@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"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>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Tamir Duberstein" <tamird@kernel.org>,
"Alexandre Courbot" <acourbot@nvidia.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Arnd Bergmann" <arnd@arndb.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
Gary Guo <gary@garyguo.net>
Subject: [PATCH 1/3] rust: macros: vtable: hide generated `HAS_` constants for required methods
Date: Tue, 11 Aug 2026 14:55:55 +0100 [thread overview]
Message-ID: <20260811-vtable_macro-v1-1-50c5aab3c211@garyguo.net> (raw)
In-Reply-To: <20260811-vtable_macro-v1-0-50c5aab3c211@garyguo.net>
These constants have to be generated as the implementation-site `#[vtable]`
invocation has no way of knowing whether the methods are required or
provided-but-overriden. However, these constants will have a fixed value so
shouldn't be used. Thus, hide them.
Signed-off-by: Gary Guo <gary@garyguo.net>
---
rust/macros/vtable.rs | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/rust/macros/vtable.rs b/rust/macros/vtable.rs
index c6510b0c4ea1..e28976a5919f 100644
--- a/rust/macros/vtable.rs
+++ b/rust/macros/vtable.rs
@@ -9,7 +9,10 @@
Ident,
TokenStream, //
};
-use quote::ToTokens;
+use quote::{
+ quote,
+ ToTokens, //
+};
use syn::{
parse_quote,
Error,
@@ -40,12 +43,18 @@ fn handle_trait(mut item: ItemTrait) -> Result<ItemTrait> {
// We don't know on the implementation-site whether a method is required or provided
// so we have to generate a const for all methods.
+ // However, hide it for required methods as it will always be true.
+ let doc = if fn_item.default.is_some() {
+ let comment =
+ format!("Indicates if the `{name}` method is overridden by the implementor.");
+ quote!(#[doc = #comment])
+ } else {
+ quote!(#[doc(hidden)])
+ };
let cfg_attrs = crate::helpers::gather_cfg_attrs(&fn_item.attrs);
- let comment =
- format!("Indicates if the `{name}` method is overridden by the implementor.");
gen_items.push(parse_quote! {
#(#cfg_attrs)*
- #[doc = #comment]
+ #doc
const #gen_const_name: bool = false;
});
}
--
2.54.0
next prev parent reply other threads:[~2026-08-11 13:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 13:55 [PATCH 0/3] rust: macros: vtable: add `#[optional]` attribute Gary Guo
2026-08-11 13:55 ` Gary Guo [this message]
2026-08-11 13:55 ` [PATCH 2/3] " Gary Guo
2026-08-11 13:55 ` [PATCH 3/3] rust: misc: use `#[optional]` attribute of `#[vtable]` macro Gary Guo
2026-10-02 13:17 ` Miguel Ojeda
2026-10-02 13:55 ` Greg Kroah-Hartman
2026-10-02 19:10 ` [PATCH 0/3] rust: macros: vtable: add `#[optional]` attribute Miguel Ojeda
2026-10-02 20:37 ` Gary Guo
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=20260811-vtable_macro-v1-1-50c5aab3c211@garyguo.net \
--to=gary@garyguo.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=arnd@arndb.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tamird@kernel.org \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/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®