mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
rust: macros: vtable: hide generated HAS_ constants for required methods
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-overridden. However, these constants will have a fixed value so shouldn't be used. Thus, hide them. Signed-off-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260811-vtable_macro-v1-1-50c5aab3c211@garyguo.net [ Reworded for typo. - Miguel ] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
547948954f
commit
5ec807292c
|
|
@ -9,7 +9,10 @@
|
|||
Ident,
|
||||
TokenStream, //
|
||||
};
|
||||
use quote::ToTokens;
|
||||
use quote::{
|
||||
quote,
|
||||
ToTokens, //
|
||||
};
|
||||
use syn::{
|
||||
parse_quote,
|
||||
Error,
|
||||
|
|
@ -56,12 +59,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;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user