[PATCH 1/3] rust: macros: vtable: hide generated `HAS_` constants for required methods

From: Gary Guo

Date: Tue Aug 11 2026 - 10:00:32 EST


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@xxxxxxxxxxx>
---
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