Skip to content

Commit

Permalink
rust: macros: vtable: fix HAS_* redefinition (gen_const_name)
Browse files Browse the repository at this point in the history
If we define the same function name twice in a trait (using `#[cfg]`),
the `vtable` macro will redefine its `gen_const_name`, e.g. this will
define `HAS_BAR` twice:

    #[vtable]
    pub trait Foo {
        #[cfg(CONFIG_X)]
        fn bar();

        #[cfg(not(CONFIG_X))]
        fn bar(x: usize);
    }

Fixes: b44becc ("rust: macros: add `#[vtable]` proc macro")
Signed-off-by: Qingsong Chen <[email protected]>
Reviewed-by: Andreas Hindborg <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
Reviewed-by: Sergio González Collado <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Miguel Ojeda <[email protected]>
  • Loading branch information
cqs21 authored and ojeda committed Aug 9, 2023
1 parent 52a93d3 commit 3fa7187
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions rust/macros/vtable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub(crate) fn vtable(_attr: TokenStream, ts: TokenStream) -> TokenStream {
const {gen_const_name}: bool = false;",
)
.unwrap();
consts.insert(gen_const_name);
}
} else {
const_items = "const USE_VTABLE_ATTR: () = ();".to_owned();
Expand Down

0 comments on commit 3fa7187

Please sign in to comment.